php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73516 Static variable and pointer problem
Submitted: 2016-11-14 13:42 UTC Modified: 2020-01-08 13:41 UTC
From: info at project dot mn Assigned: nikic (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.6.28 OS: Any OS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
6 + 33 = ?
Subscribe to this entry?

 
 [2016-11-14 13:42 UTC] info at project dot mn
Description:
------------
Object oriented concept not work when i use pointer(&) on static variable.Static variable of Parent and child class has diffrent value at same time


Test script:
---------------
class a1{
    public static $obj='';
}
class b1 extends a1{
    
}


class c{
    public $forprint='cccObject';
}
class d{
    public $forprint='dddObject';
}

$c=new c();
$d=new d();
b1::$obj=& $d;
a1::$obj=& $c;
echo b1::$obj->forprint;
//out put must be print cccObject but it print dddObject in php

Actual result:
--------------
dddObject

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-08 13:41 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-01-08 13:41 UTC] nikic@php.net
This has been fixed in PHP 7.3, where we removed the internal use of references for static class members.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 13:01:30 2024 UTC