Bug #81467 [Opn->Nab]: (object) casting of array should validate keynames
| From: | requinix@php.net | Date: | Thu, 23 Sep 2021 00:26:30 +0000 |
| Subject: | Bug #81467 [Opn->Nab]: (object) casting of array should validate keynames | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-236765@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: Not a bug
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:
Like I said, maybe an array would be better.
Previous Comments:
------------------------------------------------------------------------
[2021-09-23 00:25:43] wyattbiker at gmail dot com
I think what threw me off is the fact that the property name is a number. Unusual for sure.
------------------------------------------------------------------------
[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?
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=81467
--
Edit this bug report at https://bugs.php.net/bug.php?id=81467&edit=1