note 44189 deleted from language.functions by peehaa
| From: | peehaa@php.net | Date: | Wed, 24 Jul 2013 19:52:02 +0000 |
| Subject: | note 44189 deleted from language.functions by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195760@lists.php.net to get a copy of this message | ||
Note Submitter: jose at rondamagazine dot com
----
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).