call_user_methodSynopsis
Descriptioncall_user_method() provides an alternate syntax for calling object methods. This function is primarily useful as a way to dynamically call methods at runtime without requiring eval() . Normally, methods are called with the following syntax: $object->method ('arg one', 'arg two', ...); Calling the same method using call_user_method() would look like this: call_user_method ('method', $object, 'arg one', 'arg two', ...); Warningcall_user_method() is deprecated (as of PHP 4.0.5). call_user_func() should be used in place of this function. The following syntax for call_user_func() duplicates the functionality of call_user_method() : call_user_func(array(&$object, 'method'), 'arg one', 'arg two', ...) See alsoTo call a function in the same manner: To pass a variable number of arguments to a method (or function): ExampleExample 100. Call a member function using call_user_method() class banana { var $peeled; function banana () { $this->peeled = FALSE; } function peel () { $this->peeled = TRUE; } function eat () { if ($this->peeled) { print 'Yum!'; } else { print 'Bleck! Ever considered peeling your bananas <i>before</i> eating them?'; } } } $banana = new banana (); call_user_method ('eat', $banana);
PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing
(Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch).
This material may be distributed only subject to the terms and conditions set forth
in the Open Publication License, v1.0 or later (the latest version is presently available at
http://www.opencontent.org/openpub/).
The authors of this book have elected not to choose any options under the OPL. This online book was obtained
from http://www.fooassociates.com/phpfer/
and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4
for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All
persons and entities shall have neither liability nor responsibility to any person or entity with respect to
any loss or damage arising from the information contained in this book.
|