Req #65296 [Opn]: Support named parameters in constructors to inline initialize objects with new()

From: Date: Fri, 19 Jul 2013 10:25:41 +0000
Subject: Req #65296 [Opn]: Support named parameters in constructors to inline initialize objects with new()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-180341@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65296&edit=1

 ID:                 65296
 User updated by:    llmll at gmx dot de
 Reported by:        llmll at gmx dot de
-Summary:            Support amed parameters in constructors to inline
                     initialize objects with new()
+Summary:            Support named parameters in constructors to inline
                     initialize objects with new()
 Status:             Open
 Type:               Feature/Change Request
 Package:            Scripting Engine problem
 Operating System:   any
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

typo in summary corrected


Previous Comments:
------------------------------------------------------------------------
[2013-07-19 10:20:30] llmll at gmx dot de

Description:
------------
As PHP does not support *real* overloading by different parameter sets, arrays are being used for
dynamic parameters as well as for object initialization in constructors.

However arrays use strings as keys, which kills syntax highlighting and refactoring capabilities in
IDEs.

PHP engine should provide a way to initialize an object inline by dynamically providing parameters
to new().


Test script:
---------------
$object = new Object({
    StringMember: "content",
    Counter: 42,
    ArrayMember: ["old" => "way"]
});

Expected result:
----------------
$object->StringMember = "content";
$object->Counter = 42;
$object->ArrayMember = array("old" => "way");
$object->MoreProperties = "stay untouched";

Actual result:
--------------
not possible.


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65296&edit=1


Thread (12 messages)

« previous php.bugs (#180341) next »