|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-11-18 15:17 UTC] felipensp at gmail dot com
Description:
------------
Only occur error when inside a block. (e.g. if, empty block, ...)
Reproduce code:
---------------
<?php
$i = 0;
a:
// No error
class foo { }
// Produces error
// Fatal error: Cannot redeclare class foo
/*
{
class foo { }
}
*/
if ($i++ != 4) goto a;
Expected result:
----------------
Error ?
Actual result:
--------------
Error whenever declaring inside a block.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 09 01:00:01 2025 UTC |
class foo { } Is considered by the engine to be an "unconditional class declaration". This allows the class to be bound to the execution context at compile time and the runtime instruction to be erased. { class foo { } } Is considered by the engine to be a "conditional class declaration". This prevents the compiler from performing an early (unconditional) class binding, so it has to leave the binding instruction in the runtime code. Since the instruction is executed at runtime, it is potentially performed more than once. Put more simply: $a = 'foo'; class bar { } $b = 'baz'; Is turned into: class bar { } $a = 'foo'; $b = 'baz'; Whereas: $a = 'foo'; { class bar { } } $b = 'baz'; Is left alone. This is a deliberate design in the engine meant to reduce the speed impact caused by classes.