Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Prado\Data\SqlMap\DataMapper\TPropertyAccess::get" do not work when object instanceof \ArrayAccess #615

Open
hnlxl opened this issue Nov 26, 2016 · 3 comments

Comments

@hnlxl
Copy link

hnlxl commented Nov 26, 2016

			if(is_array($object) || $object instanceof \ArrayAccess)
			{
				if(array_key_exists($prop, $object))
					$object = $object[$prop];
				else
					throw new TInvalidPropertyException('sqlmap_invalid_property',$path);
			}

My PHP version is 5.6, array_key_exists is not work with \ArrayAccess, always return false. I think "ArrayAccess::offsetExists " is not correct too.

@ctrlaltca
Copy link
Member

The Prado\Data* part of the framework (including TActiveRecord/SqlMap) has not been tested yet in prado4. You'd better stick with prado 3.3 until we sort out all the problems.

@hnlxl
Copy link
Author

hnlxl commented Nov 28, 2016

I has avoid this problem by "object.toArray" before calling insert method.

@LCSKJ
Copy link
Member

LCSKJ commented Dec 16, 2016

This assumes that your object implements such a toArray() method which is not directly required by ArrayAccess interface. I would suggest to create a separate "else if" block for objects implementing ArrayAccess - somthing like this:

[...]
if(is_array($object))
{
  [...]
}
else if($object instanceof \ArrayAccess)
{
  if($object->offsetExists($prop))
    $object = $object->offsetGet($prop);
  else
    throw new TInvalidPropertyException('sqlmap_invalid_property',$path);
}
else if(is_object($object))
{
[...]

Only constraint would be a bad interface implementation, but i think we can leave this up to the deveoloper. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants