Re: Return type hints

From: Date: Mon, 07 Apr 2008 11:07:31 +0000
Subject: Re: Return type hints
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-36837@lists.php.net to get a copy of this message
Em Seg, 2008-04-07 às 15:48 +1000, Timothy Chandler escreveu: > I guess I should say it before anyone else does... > > "It's not the PHP way" > Do you mean the way that i initially suggest? Anyway return type hints (probably)? will implemented, at least it was accepted in 'Minutes PHP Developers Meeting'. As far as i know, just wasn't decided the syntax. > - Timothy Chandler > Simple Site Solutions > > Felipe Pena wrote: > > Hello ladies and gentlemen, > > > > I made a patch that implements an experimental return type hint, > > therefore we need discuss much about this yet, right? :) > > > > My idea uses (php-type) and +className as notation, see below. > > > > - PHP types > > > > function (string) foo(...) { } // Unicode string too > > function (object) foo(...) { } // Strict > > function (array) foo(...) { } // Strict > > function (bool) foo(...) { } // Strict > > function (int) foo(...) { } // Accepts numeric string > > function (double) foo(...) { } // Accepts numeric string > > > > > > :: Question --------------------------- > > - Add (resource), (unicode), (void) ? | > > --------------------------------------- > > > > - Userland types (like actual parameter type-hint) > > > > function +className foo(...) { } > > function +interfaceName foo(...) { } > > // Uses the class/interface 'int', not the type > > function +int foo(...) { } > > > > :: Question ---------------------------- > > - Weird syntax? | > > ---------------------------------------- > > > > :: Examples ------------------------------------------------ > > > > interface Itest { } > > class bar implements Itest { } > > class foo extends bar { } > > > > class test { > > static public function +Itest testing($instance) { > > return $instance; > > } > > } > > > > test::testing(new bar); > > test::testing(new foo); > > test::testing(new stdclass); // Error! > > // Catchable fatal error: The returned value must implement interface > > Itest > > > > ----------------------------------------- > > > > class foo { > > public function +self getInstance() { > > return $this; > > } > > } > > > > $test = new foo; > > var_dump($test->getInstance()); // OK! > > > > object(foo)#1 (0) { > > } > > > > > > Finally, it's nice or poor syntax? > > > > What must be improved/changed? (All?) > > > > > > Patch: http://felipe.ath.cx/diff/return_type_hint.diff > > Tests: http://felipe.ath.cx/diff/tests/ > > > > > -- Regards, Felipe Pena.

« previous php.internals (#36837) next »