|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-12-28 12:34 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 12 20:00:01 2025 UTC |
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'; }