note 57870 deleted from language.oop5.decon by felipe

From: Date: Mon, 24 Mar 2008 22:46:42 +0000
Subject: note 57870 deleted from language.oop5.decon by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-137512@lists.php.net to get a copy of this message
Note Submitter: webmaster at wyrihaximus dot net ---- Just a note on the __construct() function (in my example it's the classname but it has the same effect). When you try call a function outside the class, wich calls a function wich is inside the class in construction you will get a "Call to function on undefined object" error. The first piece of code shows a failing script. The seccond piece of code shows a work-around solution . Examples: The wrong code: <?php function foo($bar) { global $example; $example->friend(); } class example_class { function example_class() { foo('bar'); } function friend() { // Uhhh :) } } $example = new example_class; ?> The working code: <?php function foo($bar) { global $example; $example->friend(); } class example_class { function example_class() { // Some other code } function example_class_step2() { foo('bar'); } function friend() { // Uhhh :) } } $example = new example_class; $example->example_class_step2(); ?>

« previous php.notes (#137512) next »