|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-08-07 22:02 UTC] phpbug at trash-mail dot de
Description:
------------
This issue is related to #24608.
---quote of stas@php.net:
I have fixed it to give an error in this case and not to do things which it is not supposed to do.
---
No error is given if a __get method is defined.
Reproduce code:
---------------
$obj->dataarray['field']='...'; /* results in a call to $obj->__get('dataarray') */
Expected result:
----------------
$obj->__get() should be enabled to receive arrays. Otherwise the docs should clearly discuss this limitation and recommend an alternative procedure for overloading properties of type array.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 22:00:01 2025 UTC |
<?php class Example { protected $arr; // meant to be an array public function __get( $property ) { echo( "Getter for <strong>\$$property</strong> involved when trying to assign an array element." ); } public function __set( $property, $value ) { echo( 'Setter involved.' ); // never executed! } } $example =& new Example; $example->arr['test'] = 'any value'; ?>Well here's my Test-Case for this "bug" ? <?php // This Bug testet on PHP 5.1.4 / Win32 header('Content-Type:text/plain'); class Base { function __construct() { } } class DontWork { public $and; function __construct() { $this->and = new Base(); } function __set($key, $var) { $this->and->{$key} = $var; } } $dontwork = new DontWork(); $dontwork->this['cow'] = "cry's mow"; print_r($dontwork); /** OUTPUT DontWork Object ( [and] => Base Object ( ) [this] => Array ( [cow] => cry's mow ) ) **/ class ThisWork { public $and; function __construct() { $this->and = new Base(); } function __set($key, $var) { $this->and->{$key} = $var; } function __get($key) { return $this->and->{$key} = array(); } } $thiswork = new ThisWork(); $thiswork->this['cow'] = "cry's mow"; print_r($thiswork); /** OUTPUT ThisWork Object ( [and] => Base Object ( [this] => Array ( [cow] => cry's mow ) ) ) **/ ?>