[DOC-BUGS] Doc #61877 [Com]: Float keys not cast to int like with array
[email protected] ("krina234pestro at outlook dot com") Fri, 12 Jul 2024 10:08:46 +0000
| Newsgroups | php.doc.bugs |
|---|---|
| Message-ID | <[email protected]> |
Edit report at https://bugs.php.net/bug.php?id=61877&edit=1 ID: 61877 Comment by: krina234pestro at outlook dot com Reported by: fred dot stcm at gmail dot com Summary: Float keys not cast to int like with array Status: Verified Type: Documentation Problem Package: SimpleXML related PHP Version: 5.4.1 Block user comment: N Private report: N New Comment: The behavior you’re observing is due to how SimpleXML handles array keys differently from standard PHP arrays. In SimpleXML, the array keys are treated as strings, which means that even if you cast a float to an integer, it might not behave as expected. (https://github.com)(https://www.my-fordbenefits.com) Previous Comments: ------------------------------------------------------------------------ [2023-06-16 09:48:34] bethanders at aol dot com (https://variety.com/wp-content/uploads/2018/09/rexfeatures_9064813mz.jpg?w=1000&h=563&crop=1&resize=1000%2C563)github.com (https://static01.nyt.com/images/2013/03/31/arts/31PIVEN1_SPAN/31PIVEN1-superJumbo.jpg?quality=75&auto=webp)github.com (https://www.telegraph.co.uk/content/dam/comedy/2021/10/16/TELEMMGLPICT000145291306_trans_NvBQzQNjv4BqqVzuuqpFlyLIwiB6NTmJwSX5rhseiWKOo9p9OQ-ymek.jpeg?imwidth=960)github.com (https://images.squarespace-cdn.com/content/v1/5b61f75d506fbecf8655789d/c14cde80-aa2d-453a-bc3e-4964c9149e0d/jeremy-piven.jpg?format=1000w)github.com (https://static.wikia.nocookie.net/disney/images/d/d7/Jeremy_Piven.jpg/revision/latest?cb=20180726001612)github.com (https://www.amazon.com/prime-video/actor/Jeremy-Piven/amzn1.dv.gti.785e61d6-1dd8-4777-88c4-b33c24097594/)github.com ------------------------------------------------------------------------ [2022-11-29 06:53:35] samanre32 at gmail dot com Thanks for that. (https://www.dqfansurvey.one/)github.com ------------------------------------------------------------------------ [2021-08-18 17:08:42] [email protected] > But this rule is ignored by SimpleXML object's array. There is no SimpleXML object array, to begin with. SimpleXMLElements are more like classes implementing ArrayAccess, and ArrayAccess allows arbitrary type behavior regarding the keys. Anyhow, as it is, SimpleXMLElement array access distinguishes between integer and non-integer keys; the latter are cast to string. These have fundamentally different behavior, namely integer keys are interpreted as n-th child, while string keys are interpreted as attribute names. So casting float keys to integer would be a BC break, although float keys would create invalid XML attribute names on write access, anyway. To move forward with this ticket, I'm going to change to doc problem; while there is some explanation of array access in the examples section[1], this doesn't look complete and should better be documented on the class summay page[2] (or at least linked from there). Even better yet, SimpleXML would actually implement ArrayAccess (see request #52655). If you, or anybody else, still feels float keys should be cast to integer, please pursue the RFC process[3]. [1] <https://www.php.net/manual/en/simplexml.examples-basic.php> [2] <https://www.php.net/manual/en/class.simplexmlelement.php> [3] <https://wiki.php.net/rfc/howto> ------------------------------------------------------------------------ [2020-03-27 01:04:43] [email protected] The following pull request has been associated: Patch Name: Fix #61877: Make SimpleXMLElement respect PHP's array rule On GitHub: https://github.com/php/php-src/pull/5309 Patch: https://github.com/php/php-src/pull/5309.patch ------------------------------------------------------------------------ [2012-04-30 20:58:00] [email protected] The following patch has been added/updated: Patch Name: simplexml-patch Revision: 1335819480 URL: https://bugs.php.net/patch-display.php?bug=61877&patch=simplexml-patch&revision=1335819480 ------------------------------------------------------------------------ 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=61877 -- Edit this bug report at https://bugs.php.net/bug.php?id=61877&edit=1