Edit report at https://bugs.php.net/bug.php?id=78226&edit=1
ID: 78226
User updated by: dirk dot gerigk at tui dot com
Reported by: dirk dot gerigk at tui dot com
Summary: Unexpected __set behavior
Status: Open
Type: Bug
Package: Class/Object related
Operating System: Linux
PHP Version: 7.4Git-2019-06-28 (Git)
Block user comment: N
Private report: N
New Comment:
OK, forget the side note. i have read this https://wiki.php.net/rfc/typed_properties_v2
and it is explained there.
Previous Comments:
------------------------------------------------------------------------
[2019-06-28 10:26:02] dirk dot gerigk at tui dot com
Description:
------------
Maybe it is a not implemented yet in alpha1,
but i found a unexpected behavior when using __set / __get.
I will only point to one issue i found.
So, when you use __set in a class and typ-hint a property,
the __set method is always called.
Side Note (other issue):
Is it normal that you have to make every type-hinted property nullable?
Because when you have: public string $bar;
And do: (new A)->bar;
You get: Fatal error: Uncaught TypeError: Typed property A::$bar must be string, null used
Is that wanted in that way?
Test script:
---------------
class A {
public string $bar;
public $foo;
final public function __get($name){
print "get_$name ";
}
final public function __set($name,$arg){
print "set_$name ";
}
}
$obj = new A;
$obj->bar='';
$obj->foo='';
var_export($obj);
Expected result:
----------------
A::__set_state(array( 'bar' => '', 'foo' => '', ))
Actual result:
--------------
set_bar A::__set_state(array( 'foo' => '', ))
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78226&edit=1