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(...) { } // 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/
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php