Results 1 to 3 of 3

Thread: Declare a class in a class

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2003
    Posts
    68

    Question Declare a class in a class

    Is it possible to declare a class in another class?, like:

    Code:
    class FirstClass {
      class SecondClass {
        public $fName;
        public $lName;
        public $age;
      }
    
      ...some code
    }
    I seem to remember doing this in PHP4 but I do not get it to work in PHP5.
    The reason I want to do it it to send around parameters in a nice way in the class (FirstClass). I could use an array but its nicer to use a class when coding in an IDE since it auto completes the variable names in the class when using an object.

    I have been seaching for an answer but not found much, maybe since it's hard to search for "class in class".

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Declare a class in a class

    You'll get more results if you search for "nested class". It is not possible in PHP 5. I can't remember for sure but it might have been promised for PHP 6.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2003
    Posts
    68

    Re: Declare a class in a class

    Nice, thanks for the answer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width