php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #71981 About the static variable in static method of object
Submitted: 2016-04-07 07:22 UTC Modified: 2016-04-07 12:07 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: 1783946138 at qq dot com Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5.5.34 OS: win32
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: 1783946138 at qq dot com
New email:
PHP Version: OS:

 

 [2016-04-07 07:22 UTC] 1783946138 at qq dot com
Description:
------------
I think the non-static method of class should be have independence in different object of this class.
For example,The static variable what is in the non-static method of class should not be shared in different object. 


Test script:
---------------
class Test
{
    public function print_index()
    {
         static $index=0;//the static*
         return $index++;
    }
}
$obj1=new Test;
$obj2=new Test;
                                         //I think there should be
echo $obj1->print_index().PHP_EOL;//result:0      0
echo $obj2->print_index().PHP_EOL;//result:1      0
echo $obj1->print_index().PHP_EOL;//result:2      1
echo $obj2->print_index().PHP_EOL;//result:3      1

Expected result:
----------------
0
0
1
1

Actual result:
--------------
0
1
2
3


Patches

null (last revision 2016-04-07 07:24 UTC by 1783946138 at qq dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-07 12:07 UTC] requinix@php.net
-Status: Open +Status: Wont fix -Package: PHP Language Specification +Package: Scripting Engine problem
 [2016-04-07 12:07 UTC] requinix@php.net
$obj1 and $obj2 are two instances but both have the same print_index function with the same static variable.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 14:01:29 2024 UTC