Answer the question
In order to leave comments, you need to log in
What would be the equivalent of a javascript object in PHP?
var obj = {
'a' : function(){ return 1; },
'b' : {
'ba' : function(){ return 2; },
'bb' : {
'bba' : function(){ return 3; }
}
}
}
obj.a();
obj.b.ba();
obj.b.bb.bba();
Answer the question
In order to leave comments, you need to log in
$obj = (object) [
'a' => function(){ return 1; },
'b' => (object) [
'ba' => function(){ return 2; },
'bb' => (object) [
'bba' => function(){ return 3; }
]
]
];
call_user_func($obj->a);
call_user_func($obj->b->ba);
call_user_func($obj->b->bb->bba);
$obj->a->__invoke();
$obj->b->ba->__invoke();
$obj->b->bb->bba->__invoke();
If on the knee, then like this :
$obj = [
'a' => function(){ return 1; },
'b' => [
'ba' => function(){ return 2; },
'bb' => [
'bba' => function(){ return 3; }
]
]
];
$obj['a']();
$obj['b']['ba']();
$obj['b']['bb']['bba']();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question