Closed zeleznypa closed 3 years ago
Do you think isset($data->foo)
should be different from isset($data['foo'])
?
Good question :)
Unfortunately you can't call array_key_exists
on \ArrayAccess
for this case.
I can call the property_exists
on it, but it is based on the current inner implementation of the ArrayHash
. Another \ ArrayAccess
implementation can be implemented differently.
So the answer is not 100% "no"...
I suggest not wasting time and energy on this matter :)
I though about possibilities how to do it properly, but also not found the 100% silver bullet solution.
So for my case I have own class that extends the Nette\Utils\ArrayHash
object and overwrite the method.
/**
* offsetExists null value hotfix
*
public function offsetExists($key): bool
{
return property_exists($this, (string) $key);
}
Thanks for your time David and for your more than good work.
When i call the following code:
I expect that key
foo
exists, withNULL
as value, but when I calloffsetExists
I will gainfalse
It will be better IMHO to use the property_exists instead of
isset
here