php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43324 Label scope
Submitted: 2007-11-18 15:17 UTC Modified: 2007-11-20 03:53 UTC
From: felipensp at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 6CVS-2007-11-18 (snap) OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: felipensp at gmail dot com
New email:
PHP Version: OS:

 

 [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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-18 17:00 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

There is no label scope...
 [2007-11-20 03:53 UTC] pollita@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 17:01:36 2024 UTC