#50589 [Opn]: Feature request: Short way for multiple set of class properties

From: Date: Tue, 05 Jan 2010 14:00:31 +0000
Subject: #50589 [Opn]: Feature request: Short way for multiple set of class properties
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-146358@lists.php.net to get a copy of this message
ID: 50589 User updated by: toorion at gmail dot com Reported By: toorion at gmail dot com Status: Open Bug Type: Feature/Change Request Operating System: All PHP Version: 5.3.2RC1 New Comment: Actualy not a $insideObject = { $propertyOne = '1111'; $propertyTwo = '2222'; $propertyThree = '3333'; $propertyFour = '4444'; } it seems like store data to object, but only few properties neccesary to set: $insideObject->{ $propertyOne = '1111'; $propertyTwo = '2222'; $propertyThree = '3333'; $propertyFour = '4444'; } Previous Comments: ------------------------------------------------------------------------ [2009-12-28 12:34:24] toorion at gmail dot com Description: ------------ Background: Wery often set plenty of properties together is necessary. So, for traditional way it is requre many of copy-paste action and produce much of code. Actualy, excellent way for that - short syntax of class property settings. Reproduce code: --------------- Unliked case: $myLongNameObject = new MyLongNameObject(); $myLongNameObject->property1 = '11111'; $myLongNameObject->property2 = '22222'; $myLongNameObject->property3 = '33333'; $myLongNameObject->property4 = '44444'; $myLongNameObject->property5 = '55555'; ... Match worse (sometime necessary): $myLongNameObject = new MyLongNameObject(); // Proxy pattern $myLongNameObject->insideObject->propertyOne = '1111'; $myLongNameObject->insideObject->propertyTwo = '2222'; $myLongNameObject->insideObject->propertyThree = '3334'; $myLongNameObject->insideObject->propertyFour = '4444'; ... Expected result: ---------------- More likely way: $MyLongNameObject = new MyLongNameObject() { $property1 = '1111'; $property2 = '2222'; $property3 = '4444'; $property4 = '5555'; } Or: $MyLongNameObject = new MyLongNameObject() { $insideObject = { $propertyOne = '1111'; $propertyTwo = '2222'; $propertyThree = '3333'; $propertyFour = '4444'; } } Something like this looks better :) Actual result: -------------- Now i use array and class constructor for avoid plenty of code: $MyLongNameObject = new MyLongNameObject( array( 'property1' = '1111', 'property2' = '2222', 'property3' = '3333', 'property4' = '4444' )); But, has many complications: - Cannot initialize properties of nested object - Reduce productivity - Cannot work with IDE Code Completion like in PhpEd, NetBeans, Eclipse.... - Don't work with already initialized object. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50589&edit=1

« previous php.bugs (#146358) next »