nested class declarations

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rats
Forum Newbie
Posts: 21
Joined: Fri May 31, 2002 5:55 am

nested class declarations

Post by rats »

Getting this error. Has anyone an idea what the error message refers too?
The error points to a class such as

<?php
class user
{ //the third line?

Fatal error: Class declarations may not be nested in includes/DB.php on line 3

thanks
The rest of the code was to much to post.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

check the other classes that are interpreted (included) earlier.
May be you've forgotten the closing bracket.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

A class within a class

Post by BDKR »

Does the code look somethng like....

Code: Select all

<?php

class joe_schmo
    &#123;
    # Then somewhere within
    class jane_schmo
        &#123;
        # Do stuff
        &#125;
    # End nested class
    &#125;
# End original class

?>
In short, this kind of thing is not allowed.

Later on,
Big Din K.R.
rats
Forum Newbie
Posts: 21
Joined: Fri May 31, 2002 5:55 am

nesting classes

Post by rats »

yeah found the problem..

Cant have a required_once("database.php"); inside another class.

but yes you can call a constructor of another class from within this class.

Thanks for your help.
User avatar
fatal
Forum Contributor
Posts: 118
Joined: Sat Apr 20, 2002 10:47 am
Location: East Coast

Post by fatal »

this might interest you about nested classes: http://www.php.net/source.php?url=/zend2_example.php

Its example 3
Post Reply