Req #78494 [Opn->Sus]: Creating simple object with object()

From: Date: Wed, 04 Sep 2019 20:49:55 +0000
Subject: Req #78494 [Opn->Sus]: Creating simple object with object()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222562@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78494&edit=1 ID: 78494 Updated by: requinix@php.net Reported by: geoffgedde at gmail dot com Summary: Creating simple object with object() -Status: Open +Status: Suspended Type: Feature/Change Request Package: *General Issues Operating System: Any PHP Version: 7.2.22 Block user comment: N Private report: N New Comment: This would have to be a new *syntax*, not function. As such this is a subject that needs to go through the RFC process, which you can learn about at https://wiki.php.net/rfc/howto. But honestly, I don't see the difference between object( 'name' => 'Some Name', 'id' => 123 ) and (object)[ 'name' => 'Some Name', 'id' => 123 ] Or if you really wanted a function for the sake of... appearance? then, function object(array $properties) { return (object)$properties; } object([ 'name' => 'Some Name', 'id' => 123 ]) Which is to say nothing about whether your use case would be best addressed by a real class instead of stdClass. Previous Comments: ------------------------------------------------------------------------ [2019-09-04 20:31:17] geoffgedde at gmail dot com Description: ------------ Many times I prefer the syntax and usage of Objects over Arrays, but creating objects quickly is awkward and not very readable to the entire Team. However, it would be simplified if we could use a function called object() like we do with array(). Sure we could typecast array with (object) but that could be confusing to other devs if they miss-read or typecast. Instead it would be better to do: $obj = object( 'name' => 'Some Name', 'id' => 123 ); echo $obj->name; object() is an unused function so why can't it be added in? ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78494&edit=1

« previous php.bugs (#222562) next »