note 44189 added to language.functions
| From: | jose at rondamagazine dot com | Date: | Sat, 17 Jul 2004 10:34:01 +0000 |
| Subject: | note 44189 added to language.functions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-73434@lists.php.net to get a copy of this message | ||
A PHP4 -> PHP5 migration issue:
In PHP5, you can't declare a function inside a class method and call it from inside the method.
An example:
<?php
class A {
function f() {
function inside_f() {
echo "I'm inside_f";
}
echo "I'm f";
inside_f();
}
}
?>
PHP5 reports an "Fatal error: Non-static method A::inside_f() cannot be called statically
..."
Solution: Convert inside_f() to a class method, so you can call it from f() as $this->inside_f().
This will work in PHP4 and PHP5.
And, if you don't mind PHP4 compatibility, you should probably declare inside_f() as a private
method, because it is declared inside f() for its private use (at least, that's what I believed
I was doing; only now have I discovered that the original inside_f(), as declared, is a global
function).
----
Manual Page -- http://www.php.net/manual/en/language.functions.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44189
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44189&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44189&report=yes
Search -- http://master.php.net/manage/user-notes.php