PHP abstract class constructor not working

I wish to access some of my variables in a way like this:

System->Config->URL

Which in this case 'System' is my core class, 'Config' is an array and 'URL' is an item inside the array. Here is my 'system.php' code:

<?php

abstract class System {

    public $Config;

    public function __construct() {

        $this->Config = (object) array('URL' => 'localhost');
    }
}

echo System->Config->URL;

?>

When I run the above code I just see this:

Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ';'

Which is pointing out my echo line.

Now if I eliminate the abstract idea, and use this one, that works very well!

<?php

class System {

    public $Config;

    public function __construct() {

        $this->Config = (object) array('URL' => 'localhost');
    }
}

$System = new System();
echo $System->Config->URL;

?>

I've also tried to mix up the static and abstract keywords, but that didn't worked also. I even gave up with the __construct function and made a very normal method named 'Ready', but still couldn't call that when the class is defined abstract.

Does anyone knows what's wrong here? I have seen the similar codes works very well.

Any help or idea would highly appreciated!

Answers


I'm not sure what you are trying to do. The second example works because it is right. An abstract class is a class you need to extend, and then you can instantiate that (child) class just as in your working example.

You might need to read up on what "abstract" does.


Look at the definition of an "abstract" class. It's a class that cannot be instantiated. Only the classes that inherit it can be instantiated.


Need Your Help

Implementing ceil function in Xilinx

fpga simulink xilinx

I would like to take the ceil of the signal in Simulink(Xilinx Library). So, if for instance, the signal value is 1.5, the output would be 2.

Business Objects Infoview - Export to Excel doesn't correctly autosize cell height

reporting business-objects infoview

I have a large quantity of data from Remedy that I am using in a Business Objects InfoView/Webi report. The report is exported to Excel for distribution to department management.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.