php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #55673 Compiler creates (unused) compiled variables for self::$foo
Submitted: 2011-09-12 13:47 UTC Modified: 2015-03-21 20:48 UTC
From: derick@php.net Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3SVN-2011-09-12 (SVN) 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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: derick@php.net
New email:
PHP Version: OS:

 

 [2011-09-12 13:47 UTC] derick@php.net
Description:
------------
When having the following code:

<?php
class foo {
    function bar() {
        self::$bar = 42;
    }
}
?>

The compiler generates compiled variable !0 for $bar, even though it's a class variable:

derick@whisky:/tmp$ php -dvld.active=1 -r 'class foo { function bar() { self::$bar = 42; } }'
Finding entry points
Branch analysis from position: 0
Return found
filename:       Command line code
function name:  (null)
number of ops:  2
compiled vars:  none
line     # *  op                           fetch          ext  return  operands
---------------------------------------------------------------------------------
   1     0  >   NOP                                                      
         1    > RETURN                                                   null

branch: #  0; line:     1-    1; sop:     0; eop:     1
path #1: 0, 
Class foo:
Function bar:
Finding entry points
Branch analysis from position: 0
Return found
filename:       Command line code
function name:  bar
number of ops:  4
compiled vars:  !0 = $bar
line     # *  op                           fetch          ext  return  operands
---------------------------------------------------------------------------------
         0  >   ZEND_FETCH_CLASS                              1          
         1      FETCH_W                      static member       $1      'bar'
         2      ASSIGN                                                   $1, 42
         3    > RETURN                                                   null

branch: #  0; line:     1-    1; sop:     0; eop:     3
path #1: 0, 
End of function bar.

End of class foo.
14:41 <@Derick> dmitry: I am wondering why self::$foo creates a compiled variable. Any idea?
14:42 <@Derick> dmitry: it creates it, but it's never used
14:44 <@dmitry> I see. It's probably because od simple one-pass compiler that first interpret $foo as local variable and only then as a class variable :)
14:44 <@Derick> dmitry: any way we can fix that perhaps?
14:44 <@dmitry> Derick: could you please create a bug and assign it to me
14:44 <@Derick> yes, sure




Patches

bug55673.diff (last revision 2011-09-14 15:07 UTC by laruence@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-09-12 13:48 UTC] derick@php.net
-Assigned To: +Assigned To: dmitry
 [2011-09-14 14:37 UTC] laruence@php.net
after a quick digging, I found this is caused by zend_do_early_binding, which make 
the declare_class to NOP after use it.

I will try to make a patch for this.
 [2011-09-14 15:07 UTC] laruence@php.net
The following patch has been added/updated:

Patch Name: bug55673.diff
Revision:   1316012821
URL:        https://bugs.php.net/patch-display.php?bug=55673&patch=bug55673.diff&revision=1316012821
 [2011-09-14 15:10 UTC] laruence@php.net
I have made a patch for this, and make whole test after patched. made sure that there is no new test failed after patched.
TEST RESULT:
trunk: http://pastebin.com/gMYc2Fp5
5.4branch: http://pastebin.com/7EePEE43
5.3branch: http://pastebin.com/m4wirXjr
 [2011-09-14 15:24 UTC] laruence@php.net
OOPS!, I must lost my mind, what I was doing is erease NOP opline(god know How can I read this bug as "REMOVE UNUSED NOP" opline)....

sorry, but maybe this patch is also a litte useful...
 [2011-09-14 15:29 UTC] laruence@php.net
I'd better to report another one about the NOP opline, sorry agian.
 [2011-09-15 03:59 UTC] laruence@php.net
this cv is created in fetch_simple_variable_ex,  and fetch_simple_variable_ex is used by a lot of logic, so I think we should alter the parse.y to make the class::$static_member not to denpend on a reference_variable.  I have tried, but bring in new reduce conflict.
 [2011-09-15 09:47 UTC] dmitry@php.net
-Type: Bug +Type: Feature/Change Request
 [2011-09-15 09:47 UTC] dmitry@php.net
yeah. the fix requires significant modification of grammar and compiler.
It would be good to fix it, but I'm not sure it costs the time.
In general it's not a bug, but a feature request.
 [2015-03-21 20:48 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2015-03-21 20:48 UTC] nikic@php.net
Should be fixed in PHP 7 by AST.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 16:01:33 2025 UTC