#47567 [Opn->Asn]: Problem "Overloading" arrays with __set.

From: Date: Tue, 10 Mar 2009 10:35:51 +0000
Subject: #47567 [Opn->Asn]: Problem "Overloading" arrays with __set.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-134548@lists.php.net to get a copy of this message
 ID:               47567
 Updated by:       jani@php.net
 Reported By:      vyk2rr at gmail dot com
-Status:           Open
+Status:           Assigned
 Bug Type:         Scripting Engine problem
 Operating System: Ubuntu 8.10
 PHP Version:      5.2.9
-Assigned To:      
+Assigned To:      dmitry
 New Comment:

Dmitry, you closed bug #33941 with comment "this is not fixable". Can
you explain why it isn't? :)


Previous Comments:
------------------------------------------------------------------------

[2009-03-04 23:55:47] vyk2rr at gmail dot com

Description:
------------
I can't add values to an array using __set($k, $v){...}

This look like this other bug http://bugs.php.net/bug.php?id=39449 but
is not the same

This is the same bug http://bugs.php.net/bug.php?id=33941 but is closed
:S

So I'm researching in the manual
(http://www.php.net/manual/en/language.oop5.overloading.php), but there
is nothing about it

Reproduce code:
---------------
<?php
class test {
	private $vars = array();
	public function __set($k, $v) { $this->vars[$k] = $v; }
	public function showAll(){
		echo "<pre>";
		foreach($this->vars as $k=>$v){
			echo "$k: ";
			print_r($v); echo "<br />";
		}
		echo "</pre>";
	}
}

$t = new test();
$t->a = 'one';
$t->b = 'two';
$t->c = array('one','two');
$t->c[] = 'three';
$t->c[] = 'four';
$t->d = array( );
$t->d[] = 'one';
$t->e = 'three';

$t->showAll();
?>

Expected result:
----------------
a: one
b: two
c: Array
(
    [0] => one
    [1] => two
    [2] => three
    [3] => four
)

d: Array
(
    [0] => one
)

e: three

Actual result:
--------------
a: one
b: two
c: Array
(
    [0] => one
    [1] => two
)

d: Array
(
)

e: three


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=47567&edit=1



Thread (3 messages)

« previous php.bugs (#134548) next »