php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #32347 Match overloading behavior to ArrayAccess behavior
Submitted: 2005-03-17 04:42 UTC Modified: 2005-12-08 19:06 UTC
From: auroraeosrose at hotmail dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 5CVS-2005-03-17 (dev) OS: irrelevant
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: auroraeosrose at hotmail dot com
New email:
PHP Version: OS:

 

 [2005-03-17 04:42 UTC] auroraeosrose at hotmail dot com
Description:
------------
when implementing the ArrayAccess (spl stuff) interface you can create a offsetExists() which hooks into calling isset on your object e.g. isset($object[offset]) (by the way, I love you marcus)

but when using __get and __set with objects, isset becomes absolutely useless and there is no way to tell what you've set with __set, and it's annoying to do something like returning NULL from __get and then doing is_nulls everywhere

Please please please please can we get an __isset hook somehow - spl, overloading, something???  I've read the whole argument (http://bugs.php.net/bug.php?id=29917) about how __isset would have to be called for every property, well can it be hooked so it would only be called for public or properties that regular isset shoots back false? this is a major pain in the butt, I'd take the slowdown for the functionality any day

Reproduce code:
---------------
class data implements ArrayAccess
{
	protected $array;

	public function __construct(&$array)
	{
		$this->array =& $array;
		return;
	}

	public function __get($offset)
	{
		return $this->offsetGet($offset);
	}

	public function __set($offset, $value)
	{
		return $this->offsetSet($offset, $value);
	}

	public function offsetExists($offset)
	{
		return isset($this->array[$offset]);
	}

	public function offsetGet($offset)
	{
		if(isset($this->array[$offset]))
		{
			return $this->array[$offset];
		}
		return;
	}

	public function offsetSet($offset, $value)
	{
		$this->array[$offset] = $value;
		return;
	}

	public function offsetUnset($offset)
	{
		if(isset($this->array[$offset]))
		{
			unset($this->array[$offset]);
		}
		return;
	}
}

$array = array('one' => 1, 'two' => 2, 'three' => 3, 'four' => 4);
$class = new data($array);
var_dump(isset($class['one']));
var_dump(isset($class->one));

Expected result:
----------------
bool(true)
bool(true)

Actual result:
--------------
bool(true)
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-08 19:06 UTC] auroraeosrose at hotmail dot com
__isset and __unset implemented in 5.1 - THANKS!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 08:01:30 2024 UTC