note 57870 added to language.oop5.decon
| From: | webmaster at wyrihaximus dot net | Date: | Mon, 17 Oct 2005 13:57:24 +0000 |
| Subject: | note 57870 added to language.oop5.decon | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-97118@lists.php.net to get a copy of this message | ||
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();
?>
----
Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57870
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57870&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57870&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57870&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57870&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57870&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57870&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57870&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57870&report=yes
Search -- http://master.php.net/manage/user-notes.php