Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49581 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41918 invoked from network); 8 Sep 2010 10:34:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Sep 2010 10:34:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 212.25.124.185 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 212.25.124.185 il-mr1.zend.com Received: from [212.25.124.185] ([212.25.124.185:59304] helo=il-mr1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1F/B3-13913-BB6678C4 for ; Wed, 08 Sep 2010 06:34:38 -0400 Received: from il-gw1.zend.com (unknown [10.1.1.22]) by il-mr1.zend.com (Postfix) with ESMTP id 7DC43504F6; Wed, 8 Sep 2010 13:32:48 +0300 (IDT) Received: from ws.home (10.1.10.4) by il-ex2.zend.net (10.1.1.22) with Microsoft SMTP Server id 14.0.689.0; Wed, 8 Sep 2010 13:34:22 +0300 Message-ID: <4C8766B5.7000508@zend.com> Date: Wed, 8 Sep 2010 14:34:29 +0400 User-Agent: Thunderbird 2.0.0.23 (X11/20090825) MIME-Version: 1.0 To: Derick Rethans CC: Stas Malyshev , Zeev Suraski , PHP Internals References: <4C62EC4A.9020106@sugarcrm.com> In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [PATCH] Delegate type hint/checks to alternative locations (Re: [PHP-DEV] back to 5.4 alpha) From: dmitry@zend.com (Dmitry Stogov) Hi Derick, We had a long discussion on RFC and hear you can see the summary of my opinion: I think removing the "strict" type hinting (reverting semantic back to 5.3), but keeping the new syntax and reflection API is a good decision. However I definitely against of "delegation" of type-hinting logic into different location. PHP should be a solid language with single semantic. This delegation (zend_verify_arg_type callback) allows any extension to change schematic as it want and this may lead us into situation when some scripts will work properly only with or without Xdebug (or other extension). It also restricts possibilities to optimize ZE and introduce performance lose (now each ZEND_RECV opcode have to call this callback). Anyway performance is not the main problem because the patch may be optimized to call callback only if it's defined. I would suggest to go forward with this decision partially (without callback and without zval** instead of zval*) I hope in some point we will come to conclusion about type-hinting... Thanks. Dmitry. Derick Rethans wrote: > On Wed, 11 Aug 2010, Derick Rethans wrote: > >> On Wed, 11 Aug 2010, Stas Malyshev wrote: >> >>> So I'd propose doing the following: >>> >>> 1. Moving parameter typing to a feature branch (by branching current trunk and >>> then rolling back the typing part in the trunk). >>> 2. Starting 5.4 alpha process after that basing on trunk. >>> >>> Any objections to this? >> A little bit; yes. There is indeed 0 consensus for having the strict >> typehints. However, instead of removing it altogether, and instead >> answering every mail in this thread :P, I wrote/am writing a patch that >> removes the hard type checks. It however keeps the parsed structures and >> reflection API for it. In this sense, they're actually real hints. The >> patch also adds a mechanism similariy to the zend_error_cb mechanism so >> that extensions could override the argument type checking. As my use >> case for strict checking is development I'd be happy to just move the >> hard checks into an extension. I could even offer a soft check. It also >> allows some type inference which might be useful for webservice >> introspecition generation. I am sure SOAP might have some benefit of >> this, and I know that at least pecl/dbus does. The patch is attached, >> but not ready (I haven't remove the hard checks yet because things got >> busy at work). > > I've spend some more time on this, and have attached a new patch that: > > - Removes the strict type verification, changing it back into typehints > only. > - Keeps the current syntax so that typehints create structures in the > function entries. > - Keeps the reflection API for the syntax, so that you can query the > typehints. > - Changed the API so that the verification function can also modify the > variables. > > I've also written a proof of concept extension at > svn://svn.xdebug.org/svn/php/typed and > http://svn.xdebug.org/cgi-bin/viewvc.cgi/typed/?root=php that implements > both the current strict-type verification, and a form of the "option 1" > from > http://wiki.php.net/rfc/typecheckingstrictandweak#option_1_current_type_juggeling_rules_with_e_strict_on_data_loss > (I've not done the E_STRICT warnings for all, as the RFC didn't specifiy > when data loss was considered to occur). > > Here follows an example script: > > function errorHandler( $errno, $string ) > { > global $ok; > $ok = $errno; > return true; > } > > set_error_handler( 'errorHandler' ); > > $twelve = 12; > settype( $twelve, 'float' ); > > $values = array( > true, false, > 0, 1, 12, $twelve, 12.23, > 'true', 'false', > '0', '1', '12', '12abc', '12.0', '12.34', 'foo', > array(1,2,3), array('345' => 12), > NULL, '' > ); > $funcs = array( > 'testString', 'testFloat', 'testInt', 'testNumeric', 'testScalar', 'testBool', 'testArray', > ); > > function testString( string $a ) { } > function testFloat( float $a ) { } > function testInt( int $a ) { } > function testBool( boolean $a ) { } > function testArray( array $a ) { } > function testNumeric( numeric $a ) { } > function testScalar( scalar $a ) { } > > echo "string float int numeric scalar bool array\n"; > foreach( $values as $value ) > { > foreach( $funcs as $func ) > { > $ok = true; > $func($value); > echo $ok === true ? "pass " : ( $ok === 0x1000 ? "fail " : "warn " ); > } > echo ' ', str_replace( "\n", '', var_export( $value, true ) ); > echo "\n"; > } > ?> > > And the output (with the three different validation/verification methods: > > No validation/verification: > > derick@kossu:/home/httpd/html/test/verify-arg$ php -dextension=typed.so -dtyped.mode=0 option2.php > string float int numeric scalar bool array > pass pass pass pass pass pass fail true > pass pass pass pass pass pass fail false > pass pass pass pass pass pass fail 0 > pass pass pass pass pass pass fail 1 > pass pass pass pass pass pass fail 12 > pass pass pass pass pass pass fail 12 > pass pass pass pass pass pass fail 12.23 > pass pass pass pass pass pass fail 'true' > pass pass pass pass pass pass fail 'false' > pass pass pass pass pass pass fail '0' > pass pass pass pass pass pass fail '1' > pass pass pass pass pass pass fail '12' > pass pass pass pass pass pass fail '12abc' > pass pass pass pass pass pass fail '12.0' > pass pass pass pass pass pass fail '12.34' > pass pass pass pass pass pass fail 'foo' > pass pass pass pass pass pass pass array ( 0 => 1, 1 => 2, 2 => 3,) > pass pass pass pass pass pass pass array ( 345 => 12,) > pass pass pass pass pass pass fail NULL > pass pass pass pass pass pass fail '' > > Script type-checks: > > derick@kossu:/home/httpd/html/test/verify-arg$ php -dextension=typed.so -dtyped.mode=1 option2.php > string float int numeric scalar bool array > fail fail fail fail pass pass fail true > fail fail fail fail pass pass fail false > fail fail pass pass pass fail fail 0 > fail fail pass pass pass fail fail 1 > fail fail pass pass pass fail fail 12 > fail pass fail pass pass fail fail 12 > fail pass fail pass pass fail fail 12.23 > pass fail fail fail pass fail fail 'true' > pass fail fail fail pass fail fail 'false' > pass fail fail pass pass fail fail '0' > pass fail fail pass pass fail fail '1' > pass fail fail pass pass fail fail '12' > pass fail fail fail pass fail fail '12abc' > pass fail fail pass pass fail fail '12.0' > pass fail fail pass pass fail fail '12.34' > pass fail fail fail pass fail fail 'foo' > fail fail fail fail fail fail pass array ( 0 => 1, 1 => 2, 2 => 3,) > fail fail fail fail fail fail pass array ( 345 => 12,) > fail fail fail fail fail fail fail NULL > pass fail fail fail pass fail fail '' > > "Option 1" type-casting: > > derick@kossu:/home/httpd/html/test/verify-arg$ php -dextension=typed.so -dtyped.mode=2 option2.php > string float int numeric scalar bool array > pass pass pass fail pass pass fail true > pass pass pass fail pass pass fail false > pass pass pass pass pass pass fail 0 > pass pass pass pass pass pass fail 1 > pass pass pass pass pass pass fail 12 > pass pass warn pass pass pass fail 12 > pass pass warn pass pass pass fail 12.23 > pass fail warn fail pass pass fail 'true' > pass fail warn fail pass pass fail 'false' > pass pass pass pass pass pass fail '0' > pass pass pass pass pass pass fail '1' > pass pass pass pass pass pass fail '12' > pass fail warn fail pass pass fail '12abc' > pass pass pass pass pass pass fail '12.0' > pass pass pass pass pass pass fail '12.34' > pass fail warn fail pass pass fail 'foo' > fail fail fail fail fail fail pass array ( 0 => 1, 1 => 2, 2 => 3,) > fail fail fail fail fail fail pass array ( 345 => 12,) > pass pass pass fail fail pass fail NULL > pass fail warn fail pass pass fail '' > > I'd hope to commit this patch in the next week or so, so that we can get > started with 5.4. > > regards, > Derick > >