Why can't I declare an instance variable as an array of objects in PHP?

I am writing a client management system in PHP, for use offline (that is, on a client computer). I looked at using Java or C #, but came to the conclusion that it’s easier to make a browser for all layouts for me and just install Wamp on your computers on your computer.

Through this interface, they will also be able to manage Agents (that is, sellers who will go around their area, receiving orders for the company if they do not know). This is the section that I will use in this post to demonstrate the problem I am facing.

Basically, I have 4 classes - AgentPages, AgentList, AgentDetails and AgentForm. AgentForm will have two modes - edit and new. AgentPages has a function called getPages that returns an array of instances of the other three classes. However, this does not look like a “new” keyword.

My code is as follows (only for the AgentPages class):

<?php
require_once("AgentList.php");
require_once("AgentDetails.php");
require_once("AgentForm.php");
class AgentPages {
    public function  __construct() {
        echo "Constructed";
    }
    private $pages = array("List" => new AgentList(), "Details" => new AgentDetails(), "Form" => new AgentForm());

    function getPages() {
        return $this->pages;
    }
}
?>

NetBeans 6.9 IDE PHP ( , , ), Wamp. PHP 5.3 netbeans , " : C:\wamp\www\CustomerApp_v2\Agents\AgentPages.php 20". 5.2.11 T_NEW . 20, , 20 $pages. .

20:

$AgentList = new AgentList();

- . , , - , , - .

- , ? , PHP, , , 2 .

.

,

+3
1

, ( new ). . , .

:

class AgentPages {
    public function  __construct() {
        $this->pages = array("List" => new AgentList(), "Details" => new AgentDetails(), "Form" => new AgentForm());
        echo "Constructed";
    }

    private $pages;

}
+5

Source: https://habr.com/ru/post/1757596/


All Articles