Bug #81467 [Nab->Opn]: (object) casting of array should validate keynames

From: Date: Thu, 23 Sep 2021 00:25:43 +0000
Subject: Bug #81467 [Nab->Opn]: (object) casting of array should validate keynames
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236764@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81467&edit=1 ID: 81467 User updated by: wyattbiker at gmail dot com Reported by: wyattbiker at gmail dot com Summary: (object) casting of array should validate keynames -Status: Not a bug +Status: Open Type: Bug Package: Class/Object related Operating System: mac os x PHP Version: 8.0.10 Block user comment: N Private report: N New Comment: I think what threw me off is the fact that the property name is a number. Unusual for sure. Previous Comments: ------------------------------------------------------------------------ [2021-09-23 00:23:55] requinix@php.net No problem. It's a very uncommonly used thing so most people don't know about it. ------------------------------------------------------------------------ [2021-09-22 23:57:31] wyattbiker at gmail dot com Sorry didn't realize you could use the curlies. Can you close it please. Thanks ------------------------------------------------------------------------ [2021-09-22 21:30:51] requinix@php.net It's unusual but not invalid. The syntax is part of PHP's "variable variables" feature: https://www.php.net/manual/en/language.variables.variable.php I'd say the solution here is that if the syntax for accessing your data via some object's properties is awkward then you shouldn't be using an object for the data. Arrays are fine too. ------------------------------------------------------------------------ [2021-09-22 20:46:32] dharman@php.net What is invalid about property name "20"? I appreciate you filing the bug report, but I fail to see where the bug is. The created object is a valid object with valid property names. I can access the property without any problem: <?php $x=(object) array('20'=>'abc'); echo $x->{20}; // Outputs: abc Can you explain what exactly, do you consider a bug? ------------------------------------------------------------------------ [2021-09-22 20:36:33] wyattbiker at gmail dot com Description: ------------ When casting an associative array to an object it should verify that in fact it is creating valid object property names. E.g.this should produce an error. $x=(object) array('20'=>'abc'); echo $x->20; // << ERROR obviously Test script: --------------- $x=(object) array('x20'=>'abc'); echo $x->x20; // OK $x=(object) array('20'=>'abc'); echo $x->20; // << ERROR obviously ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81467&edit=1

« previous php.bugs (#236764) next »