Posts

Showing posts with the label method

Call superclass method in object oriented PHP application

You can call parent methods using :: operator, as in example below: parent::init( 'aaa' ); This situation works also, when dealing with static methods.

PHP Function default parameter value

You can set default parameter value for method or function by giving it's initial value at argument declaration, see example: function myFunc( $number = 8 ) { } If client will pass a number to that function like myFunc( 11 ), then $number value will be 11. But if user will call it without argument or parameter, the $number variable will have value of

How to call parent constructor ?

If you write your own constructor, you propably will want to call a parent construtor first to set up a class. You can do it in that way: parent::__construct(); This can be used also to call parent methods.

How to access global variable in php ?

If you are in a function on class method scope, you can gain access to a global variable by using a global keyword. $x = 5; function myFunc() { global $x; echo $x; } Remeber that using globals usually isn't a good idea. Better idea would be divide your globals by categories/modules and store it in static variables of some classes.