Can I use only _ (underscore) for the class name?

Can I use only _ (underscore) for the class name, if so, how will the object be created, and if not, why?

 class _{

   }
+4
source share
2 answers

Yes, you can only use underscore for the class name.

class _{
  function __construct(){
    echo 'It works!';
  }
}

new _();

Conclusion:

It works!

DEMO

+4
source

manual may be your best friend.

The class name can be any valid label if it is not a PHP reserved word. A valid class name begins with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed like this: ^ [A-Za-Z_ \ x7f- \ XFF] [A-Za-z0-9_ \ x7f- \ XFF] * $.

: https://regex101.com/r/lY2aJ4/1

+5

All Articles