sangeetha
asked on
calling a function through object
Hi all,
<?php
class MyClass {
function myFunc() {
print 'This is my function in myclass';
}
}
?>
<?php
$myArr = array('theFunc' => 'myFunc()');
$theObj = new MyClass();
$theObj->$myArr['theFunc'] ;
?>
I know that the third line of this code won't work. So I need an alternate or better way of doing it.
Either the function name or the entire call should be in the array. Like:
(1) $myArr = array('theFunc' => 'myFunc()'); OR
(2) $myArr = array('theFunc' => '$theObj->myFunc()');
The actual scenario is much more complex which I can't explain it here, but a solution for this code should solve my problem.
Thank you all.
<?php
class MyClass {
function myFunc() {
print 'This is my function in myclass';
}
}
?>
<?php
$myArr = array('theFunc' => 'myFunc()');
$theObj = new MyClass();
$theObj->$myArr['theFunc']
?>
I know that the third line of this code won't work. So I need an alternate or better way of doing it.
Either the function name or the entire call should be in the array. Like:
(1) $myArr = array('theFunc' => 'myFunc()'); OR
(2) $myArr = array('theFunc' => '$theObj->myFunc()');
The actual scenario is much more complex which I can't explain it here, but a solution for this code should solve my problem.
Thank you all.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.