#25377 [Bgs]: Class variables can be added out of class definition
| From: | helly@php.net | Date: | Sat, 22 Nov 2003 19:54:47 +0000 |
| Subject: | #25377 [Bgs]: Class variables can be added out of class definition | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-50852@lists.php.net to get a copy of this message | ||
ID: 25377
Updated by: helly@php.net
Reported By: forseti at oak dot rpg dot pl
Status: Bogus
Bug Type: Class/Object related
Operating System: Windows 98 SE
PHP Version: 5CVS-2003-09-03 (dev)
New Comment:
Class variables can NOT be added onnly object variables can. That makes
PHP a language between class oriented and real object oriented
languages.
Previous Comments:
------------------------------------------------------------------------
[2003-11-18 15:36:23] sniper@php.net
This is actually a feature, not bug.
------------------------------------------------------------------------
[2003-09-03 04:16:27] forseti at oak dot rpg dot pl
Description:
------------
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:
---------------
<?php
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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=25377&edit=1