|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25377 Class variables can be added out of class definition
Submitted: 2003-09-03 04:16 UTC Modified: 2003-11-22 14:54 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: forseti at oak dot rpg dot pl Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5CVS-2003-09-03 (dev) OS: Windows 98 SE
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.
Block user comment
Status: Assign to:
Bug Type:
From: forseti at oak dot rpg dot pl
New email:
PHP Version: OS:


 [2003-09-03 04:16 UTC] forseti at oak dot rpg dot pl
Class variables can be added freely out of class declaration context. This can be done by simply assigning a value to existing object's non-existing variable. Resulting modified object remains of his old type.

Reproduce code:
class Test {
	var $a='foo';
class HintTest {
	function __construct(Test $var) {
		echo 'Variable of type Test passed';
$test1 = new Test;
$test2 = new Test;
$test2->b = 'bar';
$test3 = new Test;
echo '<pre>test1: ';print_r($test1);echo '</pre>';
echo '<pre>test2: ';print_r($test2);echo '</pre>';
echo '<pre>test3: ';print_r($test3);echo '</pre>';
$hint = new HintTest($test2);

Expected result:
Adding new class variables this way shouldn't be possible because modified object is no longer of the same type. 
And as last line shows it is treated by engine as such.

Actual result:
Modified object is nevertheless treated as if it was of Test type.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-18 15:36 UTC]
This is actually a feature, not bug.

 [2003-11-22 14:54 UTC]
Class variables can NOT be added onnly object variables can. That makes PHP a language between class oriented and real object oriented languages.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 01 16:01:31 2024 UTC