Bug #78226 [NEW]: Unexpected __set behavior
| From: | dirk dot gerigk at tui dot com | Date: | Fri, 28 Jun 2019 10:26:02 +0000 |
| Subject: | Bug #78226 [NEW]: Unexpected __set behavior | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-221538@lists.php.net to get a copy of this message | ||
From: dirk dot gerigk at tui dot com
Operating system: Linux
PHP version: 7.4Git-2019-06-28 (Git)
Package: Class/Object related
Bug Type: Bug
Bug description:Unexpected __set behavior
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 bug report at https://bugs.php.net/bug.php?id=78226&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=78226&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=78226&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=78226&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=78226&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78226&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78226&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78226&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78226&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78226&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78226&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78226&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78226&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78226&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=78226&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=78226&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78226&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78226&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78226&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78226&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78226&r=mysqlcfg