php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #50589 toorion
Submitted: 2009-12-28 12:34 UTC Modified: 2010-12-01 16:59 UTC
From: toorion at gmail dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 6.0.0 OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: toorion at gmail dot com
New email:
PHP Version: OS:

 

 [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.




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-05 14:00 UTC] toorion at gmail dot com
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';
}
 [2010-12-01 16:28 UTC] jani@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2010-12-01 16:28 UTC] jani@php.net
Use arrays instead.
 [2010-12-01 16:59 UTC] toorion at gmail dot com
-Summary: Feature request: Short way for multiple set of class properties +Summary: toorion -PHP Version: 5.3.2RC1 +PHP Version: 6.0.0
 [2010-12-01 16:59 UTC] toorion at gmail dot com
>Use arrays instead.
Hm, it is exactly I write few lines up. So, it is useless.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 15:01:36 2025 UTC