PHP How to instance an inner class

I have a class called Pages used as a namespace, like this:


static class Pages
    class Page
        public $Name;
        public $Title;

        public function __construct($Name, $Title)
            $this->Name = $Name;
            $this->Title = $Title;




$g_Pages = new Pages::Page("My Name", "My Title");


Unfortunately, I'm getting a Parse error: syntax error, unexpected 'Page' (T_STRING), expecting variable (T_VARIABLE) or '$'

What am I doing wrong?


If you're trying to use the inner class as a namespace, just use namespaces. Ex:

namespace Pages;
class Page { }

Then you can access the class through:

$g_Pages = new \Pages\Page("My Name", "My Title");

Unfortunately nested classes are not a language feature of PHP.

The below SO page explains this in detail.

Nested or Inner Class in PHP

Need Your Help

Move a viewController to the back of the window

iphone ios uiviewcontroller sparrow-framework

I'm using the open source ShareKit framework. It requires a viewController to modally draw its share menus and such. I'm making a game with the Sparrow framework, which just adds a custom SPView ...

Doctrine DQL join on nullable columns

php mysql doctrine-orm

Is it possible to join two tables based on a null-able column with the Doctrine QueryBuilder?