php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38370 __set not triggered when overloading with array (related: #24608)
Submitted: 2006-08-07 22:02 UTC Modified: 2006-08-16 01:00 UTC
Votes:16
Avg. Score:5.0 ± 0.0
Reproduced:16 of 16 (100.0%)
Same Version:14 (87.5%)
Same OS:15 (93.8%)
From: phpbug at trash-mail dot de Assigned:
Status: No Feedback Package: Class/Object related
PHP Version: 5.1.4 OS: Windows XP
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: phpbug at trash-mail dot de
New email:
PHP Version: OS:

 

 [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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-08 12:00 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2006-08-13 10:43 UTC] anything at trash-mail dot de
<?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';
?>
 [2006-08-16 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2006-08-18 16:38 UTC] dkr at mindwerk dot de
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
                )

        )

)
**/

?>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC