F
F
Froskyta_12019-06-22 09:01:02
PHP
Froskyta_1, 2019-06-22 09:01:02

How to connect a trait?

why can't my class find the trait?
I sort of understood the theme of the trait. But when it came to practice, I simply could not connect the trait to the class, to put it mildly.
My folder structure was like this:
1.index.php
2.main.php(class)
3.single.php(train)
index.php

<?php

  require_once 'main.php';
?>

main.php
<?php

  /**
   * 
   */
  class main
  {
    
    use single;
  }
?>

single.php
<?php

  trait single{
    
  }
?>

It seems that everything is clear and understandable and everything should work. But it can't find the trait, throwing the following error:
Fatal error: Trait 'single' not found in C:\OSPanel\domains\text\public\main.php on line 9

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kafkiansky, 2019-06-22
@mad_maximus

You haven't enabled the trait.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question