Re: Return type hints
| From: | Timothy Chandler | Date: | Mon, 07 Apr 2008 05:48:50 +0000 |
| Subject: | Re: Return type hints | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-36832@lists.php.net to get a copy of this message | ||
I guess I should say it before anyone else does...
"It's not the PHP way"
- 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(...) { } // Strictfunction (int) foo(...) { } // Accepts numeric stringfunction (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/