Skip to content

Commit

Permalink
Merge 80bd47c into bab90a0
Browse files Browse the repository at this point in the history
  • Loading branch information
hexusdev committed Sep 27, 2016
2 parents bab90a0 + 80bd47c commit e01630e
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/mp.php
Expand Up @@ -285,6 +285,22 @@ function getValue($src, $propertyName, $default = null, $delimiter = '.')
*/
function &getValueByRef(&$src, $propertyName, $default = null, $delimiter = '.')
{
if (is_array($src) && array_key_exists($propertyName, $src)) {
return $src[$propertyName];
}
$isObject = is_object($src);
if ($isObject && isset($src->{$propertyName})) {
// if it's not magic method, return reference
if (property_exists($src, $propertyName)) {
return $src->{$propertyName};
// otherwise (it's __get()) calling $src->{$propertyName} will generate PHP notice:
// indirect modification of overloaded property has no effect.
// Therefore we return link to temp variable instead of link to variable itself.
} else {
$tmp = $src->{$propertyName};
return $tmp;
}
}
if ($delimiter && $pos = strpos($propertyName, $delimiter)) {
// head(a.b.c) = a
// tail(a.b.c) = b.c
Expand All @@ -297,24 +313,7 @@ function &getValueByRef(&$src, $propertyName, $default = null, $delimiter = '.')
$delimiter
);
}

if (is_array($src)) {
if (array_key_exists($propertyName, $src)) {
return $src[$propertyName];
}
} elseif (is_object($src)) {
if (isset($src->{$propertyName})) {
// if it's not magic method, return reference
if (property_exists($src, $propertyName)) {
return $src->{$propertyName};
// otherwise (it's __get()) calling $src->{$propertyName} will generate PHP notice:
// indirect modification of overloaded property has no effect.
// Therefore we return link to temp variable instead of link to variable itself.
} else {
$tmp = $src->{$propertyName};
return $tmp;
}
}
if ($isObject) {
$camelPropName = Str::toCamelCase($propertyName);
$methods = [
'get' . $camelPropName,
Expand Down

0 comments on commit e01630e

Please sign in to comment.