|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-02-03 19:34 UTC] nikic@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: nikic
[2021-02-03 19:34 UTC] nikic@php.net
[2021-02-03 19:34 UTC] vali dot dr at gmail dot com
-Status: Closed
+Status: Open
[2021-02-03 19:34 UTC] vali dot dr at gmail dot com
[2021-02-03 19:47 UTC] nikic@php.net
-Status: Open
+Status: Not a bug
[2021-02-03 19:47 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 20 18:00:01 2025 UTC |
Description: ------------ If you unset a property on a class, the __get magic method gets called (good), but it's return must match the original, now unset, property type. (bug?) There should be a way to fully remove that property, either by reflection or unset (including the return time) Test script: --------------- <?php declare(strict_types=1); class Sample { public int $foo = 123; # Start as in INT public function __construct() { unset($this->foo); # Remove the property } public function __get(string $name) { # Gets called, since `foo` dies not exist. echo "__GET\n"; # Validate that it's called return "string"; # Cannot return string since foo was an int... } } $test = new Sample(); echo $test->foo; # Throws error, since __get returns a string instead of an int Expected result: ---------------- __GET string Actual result: -------------- __GET PHP Fatal error: Uncaught TypeError: Cannot assign string to property Sample::$foo of type int in ... .php:18 Stack trace: #0 {main} thrown in ...