5

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 _{

   }
3
  • 3
    try and see what happens Commented Jun 17, 2015 at 7:35
  • I don't know why this question get up voted while it should be down voted Commented Jun 17, 2015 at 7:57
  • @rajeshpatel could you mark one answer as accepted to mark this question answered? Commented Jun 17, 2015 at 19:32

2 Answers 2

6

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

Sign up to request clarification or add additional context in comments.

Comments

4

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

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

new _();

Output:

It works!

DEMO

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.