note 106831 deleted from keyword.class by sobak
| From: | sobak@php.net | Date: | Sat, 12 Nov 2016 09:36:46 +0000 |
| Subject: | note 106831 deleted from keyword.class by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207079@lists.php.net to get a copy of this message | ||
Note Submitter: pov at fingerprint.fr
----
I just discovered a behaviour that has to be mentioned.
Let's consider the following file
<?php
Foo::bar();
exit;
class Foo {
function bar() { echo 'yep, this is Foo::bar'; }
}
?>
You may expect :
- an error on the Foo::bar call, because the class is not defined
- removing the code after the exit without side-effect
But it won't, and it will output the string !
It seems every class definition is executed at parse-time.
But without errors; if your file is
<?php
Foo::bar();
exit;
class Foo {
function bar() { echo 'yep, this is Foo::bar'; }
}
class Foo {
function bar() { echo 'yep, this is another Foo::bar'; }
}
?>
it will still output the first string, not doing any "Already exiting class" error !
So if you intend preventing a double include by doing in an included file :
<?php
if (class_exists('Foo')) { return; }
class Foo {
static function register() { ... }
}
Foo::register();
?>
the Foo::register method won't be called !
Very strange development choice; I suppose it is due to ascending compatibility.
Hope it can help...