Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added plucking of object's that implement __get()

  • Loading branch information...
commit 696e1dc2a6723b8bbae37498d08026a31d32245a 1 parent 54c3cc1
tijmenb authored
Showing with 11 additions and 3 deletions.
  1. +11 −3 underscore.php
14 underscore.php
View
@@ -106,11 +106,19 @@ public function pluck($collection=null, $key=null) {
$collection = (array) self::_collection($collection);
$return = array();
+
foreach($collection as $item) {
- foreach($item as $k=>$v) {
- if($k === $key) $return[] = $v;
- }
+ if (is_object($item)) {
+ if (is_callable(array($item, '__get')) || isset($item->{$key})) {
+ $return[] = $item->{$key};
+ }
+ } else {
+ foreach($item as $k=>$v) {
+ if($k === $key) $return[] = $v;
+ }
+ }
}
+
return self::_wrap($return);
}
Please sign in to comment.
Something went wrong with that request. Please try again.