Re: [VOTE] Alternative typehinting syntax for accessors
| From: | Crypto Compress | Date: | Mon, 21 Jan 2013 23:35:45 +0000 |
| Subject: | Re: [VOTE] Alternative typehinting syntax for accessors | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-65062@lists.php.net to get a copy of this message | ||
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 :) NikitaNonetheless 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"?