Can I pass an object reference as a function argument? eg:
$a = new Smarty(); foo($a); // передаем ссылку на объект чтобы использовать его методы внутри функции //и в последствии передать эту ссылку другой функции. Yes, that's right, you can do that.
class A { public function test(B $b) { $b->testMethod(); } } class B { public function testMethod() { echo 'I\'m from class B<br/>'; } } function testFunction(B $b) { $b->testMethod(); } $a = new A(); $b = new B(); $a->test($b); testFunction($b); both will derive I'm from class B
In PHP, objects are passed by reference . So " passing an object reference as a function argument " is not only the right path , but the only one .
Source: https://ru.stackoverflow.com/questions/632481/
All Articles