Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:37803 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41285 invoked from network); 22 May 2008 15:23:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 May 2008 15:23:15 -0000 Authentication-Results: pb1.pair.com smtp.mail=sv_forums@fmethod.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=sv_forums@fmethod.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fmethod.com from 69.16.228.148 cause and error) X-PHP-List-Original-Sender: sv_forums@fmethod.com X-Host-Fingerprint: 69.16.228.148 unknown Linux 2.4/2.6 Received: from [69.16.228.148] ([69.16.228.148:51144] helo=host.fmethod.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7D/E6-34040-3EF85384 for ; Thu, 22 May 2008 11:23:15 -0400 Received: from [83.228.56.37] (port=1756 helo=pc) by host.fmethod.com with esmtpa (Exim 4.68) (envelope-from ) id 1JzCdL-0005Nr-Rj for internals@lists.php.net; Thu, 22 May 2008 10:23:12 -0500 Message-ID: <51CC3BDA2E7643C0AB6CA257D2CD2CCE@pc> To: References: <10845a340805220458i3f44bdf0p4d9d3f452ebc5c32@mail.gmail.com> Date: Thu, 22 May 2008 18:23:03 +0300 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="UTF-8"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - host.fmethod.com X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - fmethod.com Subject: Re: [PHP-DEV] Getting Default Values via reflection. From: sv_forums@fmethod.com ("Stan Vassilev | FM") Hi, Please notice that I said "followed by required ones". function foo($a = null, $b) {} The above definition is allowed and the compiler won't complain, but actually that "= null" is completely lost, including in Reflection. Regards, Stan Vassilev > 2008/5/22 Stan Vassilev | FM : >> >> Hi, >> >> Actually PHP ignores default values on parameters followed by required >> ones. >> You can't fetch the default value even via Reflection. >> This is easily detected at compile time so I wonder why the compiler >> doesn't >> warn. >> >> Regards, >> Stan Vassilev > > I'm not sure this is what you mean, but I use the following function > in my debugging logic. > > function getArgs($s_Function, array $a_PassedParams = array()) { > $a_Arguments = array(); > if ('' !== $s_Function) { > $rf_This = new ReflectionFunction($s_Function); > foreach($rf_This->getParameters() as $i_Param => $rp_Param) { > $a_Arguments[$rp_Param->getName()] = $i_Param < > count($a_PassedParams) ? $a_PassedParams[$i_Param] : > $rp_Param->getDefaultValue() . ' (Default)'; > } > } > return $a_Arguments; > } > > function foo($required, $optional = 'snafu', $also_optional = 'sins') { > print_r(getArgss(__FUNCTION__, func_get_args())); > } > > foo('fred'); > foo('bob', 'jim'); > > outputs ... > > Array > ( > [required] => fred > [optional] => snafu (Default) > [also_optional] => sins (Default) > ) > Array > ( > [required] => bob > [optional] => jim > [also_optional] => sins (Default) > ) > > -- > ----- > Richard Quadling > Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 > "Standing on the shoulders of some very clever giants!" > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >