Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

oop

php

Can i use only _ (underscore) for the name of the class if yes then how object will be create and if no then why not?

 class _{

   }
like image 744
Rajesh Patel Avatar asked Jan 09 '23 03:01

Rajesh Patel


1 Answers

The manual might be your best friend.

The class name can be any valid label, provided it is not a PHP reserved word. A valid class name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: ^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$.

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

like image 200
Ofir Baruch Avatar answered Jan 16 '23 06:01

Ofir Baruch