Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:47655 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12939 invoked from network); 27 Mar 2010 16:15:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Mar 2010 16:15:26 -0000 Received: from [127.0.0.1] ([127.0.0.1:26189]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id 70/53-20638-E1F2EAB4 for ; Sat, 27 Mar 2010 11:15:26 -0500 X-Host-Fingerprint: 79.165.172.25 unknown Received: from [79.165.172.25] ([79.165.172.25:7022] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A5/33-20638-32C2EAB4 for ; Sat, 27 Mar 2010 11:02:43 -0500 Message-ID: To: internals@lists.php.net Date: Sat, 27 Mar 2010 19:02:40 +0300 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100301 Fedora/3.0.3-1.fc12 Thunderbird/3.0.3 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 79.165.172.25 Subject: Proposal: shorthand object property setting syntax. From: toorion@gmail.com (Toorion) Very often (for example when work with dom or UI object) setting plenty of object properties is require. At this time we has not a lot options. Standard way looks very dirty and be reason of more copy-paste-work. Reproduce code: --------------- $myLongNameObject = new MyLongNameObject(); $myLongNameObject->property1 = '11111'; $myLongNameObject->property2 = '22222'; $myLongNameObject->property3 = '33333'; $myLongNameObject->property4 = '44444'; $myLongNameObject->property5 = '55555'; Or worse case: $myLongNameObject = new MyLongNameObject(); // Proxy pattern $myLongNameObject->property1 = '11111'; $myLongNameObject->property2 = '22222'; $myLongNameObject->property3 = '33333'; $myLongNameObject->insideObject = new InsideObject(); $myLongNameObject->insideObject->propertyOne = '1111'; $myLongNameObject->insideObject->propertyTwo = '2222'; $myLongNameObject->insideObject->propertyThree = '3334'; $myLongNameObject->insideObject->propertyFour = '4444'; So, apparently, that is not good. We can use special constructor code and array like parameter of constructor like this: $MyLongNameObject = new MyLongNameObject( array( 'property1' = '1111', 'property2' = '2222', ..... )); But it's look like crutch and can't extended with IDE. Match better if we can set multiple properties in one time something like this: $MyLongNameObject = new MyLongNameObject() { $property1 = '1111'; $property2 = '2222'; $property3 = '4444'; $property4 = '5555'; } And (for multiple setting properties for exists object): $MyLongNameObject = new MyLongNameObject(); $MyLongNameObject->{ $propertyOne = '1111'; $propertyTwo = '2222'; $propertyThree = '3333'; $propertyFour = '4444'; } So, this way can help in many cases with initialization long OOP structures and economy lot of time for programming, debugging and refactoring code.