PHP对象在另一个对象里面

I have an object $user.

var_dump($user) will output this:

object(user)#12 (1) {
  ["mylog"]=> object(mylog)#13 (2) { 
    ["userid"]=> string(1) "1" 
    ["uname"]=> string(5) "admin"
  }
}

What I want to access is the "userid" property. I succeeded with

foreach($user as $otherObject=>$property)
{
     echo $property->userid;
}

My question is if I can do something like $user->OtherObjectPlaceholder->userid without needing to loop through all the properties?

You can make chaining at php for methods if you return object. This is called Fluent Interface.

class a
{
  public $a;

  public function __construct()
  {
      $this->a = new b; 
  }
}

class b {
   public $b;
}

$object = new a;
$object->a->b

create a getter in $user object and run this:

$user->getOtherObject()->userid