Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42219 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37650 invoked from network); 12 Dec 2008 05:21:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Dec 2008 05:21:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=xuefer@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=xuefer@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.142.184 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: xuefer@gmail.com X-Host-Fingerprint: 209.85.142.184 ti-out-0910.google.com Received: from [209.85.142.184] ([209.85.142.184:31267] helo=ti-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F1/10-36388-FD4F1494 for ; Fri, 12 Dec 2008 00:21:36 -0500 Received: by ti-out-0910.google.com with SMTP id u3so841201tia.17 for ; Thu, 11 Dec 2008 21:21:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:mime-version:content-type:content-transfer-encoding :content-disposition:x-google-sender-auth; bh=qfAJJubuhBpCnMQ0k5MryFxHuRWGBQ/CQUHYHmFpu6E=; b=HQHOo9ywv3kGrGbpsWOZgbUjeY9A3bH3Bf4cWcm3O746Y7P674JlSmCRI/aZD1iSEl +igNcPC4IKhIHO0UYlq8oipBt5hnkzU95TIZInZO5Om9EDw/1MxoxSVt8rehhdFrQUrI z+2Q8An2gkEk8sihUbTJdiV7Hcw09mcr3H8FI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition:x-google-sender-auth; b=EWX8gLoHxb1gN2hGvtmhqo2RTGa2+451yWHl9i/QE+GS0TY886NBcvpoYR9ZYXqd/Z s2onVAW3rSl6ByVVE1+N7TyMUFyWiSsXxNsWqUTNdnEtZYAsxlXwx2K12CguSfprfKWX NXLs6OzqwGwVuFeMl9kt32bvYgCJv1MGkLbNQ= Received: by 10.110.63.6 with SMTP id l6mr4763273tia.50.1229059292729; Thu, 11 Dec 2008 21:21:32 -0800 (PST) Received: by 10.110.53.9 with HTTP; Thu, 11 Dec 2008 21:21:32 -0800 (PST) Message-ID: <28139bc0812112121v2263ec2am1e603bf008bb1ecf@mail.gmail.com> Date: Fri, 12 Dec 2008 13:21:32 +0800 Sender: xuefer@gmail.com To: "PHP Developers Mailing List" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Google-Sender-Auth: 0c7e4dd35bcc371c Subject: 5.3 compile time still depends on runtime constants ("Default value for parameters with a class type hint can only be NULL") From: phpxcache@gmail.com (phpxcache) this is a discussion about "Default value for parameters with a class type hint can only be NULL" error let's focus our eyes on ==== zend_compile.c function zend_do_receive_arg void zend_do_receive_arg(zend_uchar op, const znode *var, const znode *offset, const znode *initialization, znode *class_type, const znode *varname, zend_uchar pass_by_reference TSRMLS_DC) { ........... if (op == ZEND_RECV_INIT) { if (Z_TYPE(initialization->u.constant) == IS_NULL || (Z_TYPE(initialization->u.constant) == IS_CONSTANT && !strcasecmp(Z_STRVAL(initialization->u.constant), "NULL"))) { cur_arg_info->allow_null = 1; } else { zend_error(E_COMPILE_ERROR, "Default value for parameters with a class type hint can only be NULL"); } } ====test.php====== u.constant) == IS_NULL 1 (true) which means it still "subst null to IS_NULL" test case 2 precondtion: let's assume ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION is working for zend_do_receive_arg, simply empty hash table EG(zend_constants) = &an_empty_hash_table before zend_compile_file break at function zend_do_receive_arg and (gdb) print Z_TYPE(initialization->u.constant) == IS_NULL 0 (false) (gdb) print Z_TYPE(initialization->u.constant) == IS_CONSTANT 0 (false) so what is that? (gdb) print Z_TYPE(initialization->u.constant) 24 (gdb) print (Z_TYPE(initialization->u.constant) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT 1 (true) ************ ok, we get the first bug (gdb) p !strcasecmp(Z_STRVAL(initialization->u.constant), "NULL")) 0 (false) why? (gdb) p Z_STRVAL(initialization->u.constant) "My\\NS\\null" this is the reason. looks likestrcasecmp is not enough here at compile time. or you could just handle abc(array $a = null) as a special case?