Am 21.01.2013 23:59, schrieb Nikita Popov:
> Sorry if it wasn't clear: The nullability stuff only applies if a
typehint
> is used. If no typehint is used, then you can freely assign null,
regardless
> of whether or not you have the "= null" in the declaration
> (no typehint = everything's valid). "public $foo;" will continue to
behave
> exactly the same way it did before :)
> Nikita
Nonetheless there is the same complication. I like to test
"half-instantiated"
objects (maybe this is common/best practice?):
<?php
class C {
public string $a;
public string $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
}
// test only a
$c = new C("foo", null); // fail
var_dump($c->a === "foo");
// test only b
$c = new C(null, "foo"); // fail
var_dump($c->b === "foo");
?>
So if i want typehinting, i have to add "= null" without any real benefit as
for testing. Current behavior doesn't restrict NULL values. Why change this?
"method-like optional values"?
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php