Req #71981 [Opn->Wfx]: About the static variable in static method of object
| From: | requinix@php.net | Date: | Thu, 07 Apr 2016 12:07:47 +0000 |
| Subject: | Req #71981 [Opn->Wfx]: About the static variable in static method of object | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200421@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71981&edit=1
ID: 71981
Updated by: requinix@php.net
Reported by: 1783946138 at qq dot com
Summary: About the static variable in static method of
object
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
-Package: PHP Language Specification
+Package: Scripting Engine problem
Operating System: win32
PHP Version: 5.5.34
Block user comment: N
Private report: N
New Comment:
$obj1 and $obj2 are two instances but both have the same print_index function with the same static
variable.
Previous Comments:
------------------------------------------------------------------------
[2016-04-07 07:22:51] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71981&edit=1