What can I add in constructors in PHP?

You can include variables, function calls, method calls, object declarations, etc, etc, etc inside your default constructor class Test { protected $protected; private static $static; function __construct() { parent::__construct(); $this->protected = 'test'; $variable_local = 'hey'; self::$static = 'im static'; $obj = new OtherClass(); $this->myMethod(); externalFunction(); } public function myMethod() { echo 'all mine'; } } function externalFunction() { 'hey, im external'; }.

You can include variables, function calls, method calls, object declarations, etc, etc, etc inside your default constructor. Class Test { protected $protected; private static $static; function __construct() { parent::__construct(); $this->protected = 'test'; $variable_local = 'hey'; self::$static = 'im static'; $obj = new OtherClass(); $this->myMethod(); externalFunction(); } public function myMethod() { echo 'all mine'; } } function externalFunction() { 'hey, im external'; }.

Thanks. Can I call echo $variable_local in a view? How can I call $this->protected in a view?

– shin Jan 11 '10 at 19:20.

Knock yourself out. Add any PHP you want. You can use $this to refer to the object being created.

But I would like to show the power of parent::__construct for use with PHP's OOP polymorphic behavior (you'll see what this is very quickly). In my example, I have created a fairly robust base class that does everything that all subclasses need to do. Here's the base class def.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions