1

HI friends here I have share my code. I am used the Nested class in this Program. When I run this code it shows the Error like this. "syntax error, unexpected T_CLASS, expecting T_FUNCTION"

  class Nest
   {
  class Display
  { 
   private $s;
   public sum($a, $b)
 { 
   $s =$a+$b; 
 }
 function show()
 {
 echo "Sum of a and b is:: ". $s;
 }
 }
 }

 new $x = Nest::Display;
 $x->sum(12, 10);
 $x->show();

I don't know what mistake i did. Any one help to solve this problem.

3
  • Are you sure you have to use nested classes? It seems 'smelly' to me. Commented Dec 10, 2012 at 13:13
  • 1
    starting here would be a good idea: php.net/manual/en/language.oop5.basic.php Commented Dec 10, 2012 at 13:15
  • I not sure is PHP having a nested class? because I am searching on web lot of article comes to nested class with PHP but all those are forums .Same as nobody said PHP don't having a nested class. Commented Dec 10, 2012 at 13:18

1 Answer 1

3

You can't have nested classes in PHP.

You may want to hear about namespaces though.

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

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.