note 106831 added to keyword.class

From: Date: Fri, 09 Dec 2011 21:22:21 +0000
Subject: note 106831 added to keyword.class
Groups: php.notes 
Request: Send a blank email to php-notes+get-185008@lists.php.net to get a copy of this message
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... ---- Server IP: 89.31.146.176 Probable Submitter: 109.69.192.35 ---- Manual Page -- http://www.php.net/manual/en/keyword.class.php Edit -- https://master.php.net/note/edit/106831 Del: integrated -- https://master.php.net/note/delete/106831/integrated Del: useless -- https://master.php.net/note/delete/106831/useless Del: bad code -- https://master.php.net/note/delete/106831/bad+code Del: spam -- https://master.php.net/note/delete/106831/spam Del: non-english -- https://master.php.net/note/delete/106831/non-english Del: in docs -- https://master.php.net/note/delete/106831/in+docs Del: other reasons-- https://master.php.net/note/delete/106831 Reject -- https://master.php.net/note/reject/106831 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#185008) next »