Bug #81467 [Opn->Fbk]: (object) casting of array should validate keynames
| From: | requinix@php.net | Date: | Wed, 22 Sep 2021 21:30:52 +0000 |
| Subject: | Bug #81467 [Opn->Fbk]: (object) casting of array should validate keynames | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-236761@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
Updated by: requinix@php.net
Reported by: wyattbiker at gmail dot com
Summary: (object) casting of array should validate keynames
-Status: Open
+Status: Feedback
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:
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.
Previous Comments:
------------------------------------------------------------------------
[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