Re: OO-problem

From: Date: Tue, 17 Apr 2001 22:19:12 +0000
Subject: Re: OO-problem
References: 1  Groups: php.lang 
Request: Send a blank email to php-lang+get-140@lists.php.net to get a copy of this message
You can't have multiple definitions for the same method. However, you can easily implement this functionality in a number of different ways: - Using default argument values (e.g., function b($var=unset) { ... }; If $var is unset, behave as if there were no arguments sent). - Declaring no argument list at all, and using func_num_args(), func_get_arg() and func_get_args() to determine what the arguments were. The reason for the behavior you discovered (which is intended) is that PHP doesn't decide which functions to call according to the argument list, but only according to the name. There's no polymorphism of that kind in PHP. Zeev At 00:33 18/4/2001, Bas Cancrinus wrote:
Hi, I'm experiencing the following problem when I try to implement an OO-model in PHP: If a class, say A, has more than 1 method with equal names, say b, and different signatures and one of these methods b of an instance A is called, then PHP always delegates that call to the first method that appears in the code. Example: class A { function b () {
      ...
} function b ($var) {
      ...
} } $anInstance = new A; $aReturnValue = $anInstance->b (...) // Won't work Is this a bug or is there any other reason for this behaviour? Thanks, Bas -- PHP Language Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-lang-unsubscribe@lists.php.net For additional commands, e-mail: php-lang-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
-- Zeev Suraski <zeev@zend.com> CTO & co-founder, Zend Technologies Ltd. http://www.zend.com/

« previous php.lang (#140) next »