[PHP-BUG] Req #70413 [NEW]: FR: support to new() keyword
[email protected] ("david dot proweb at gmail dot com")
| Newsgroups | php.standards |
|---|---|
| Message-ID | <[email protected]> |
From: david dot proweb at gmail dot com
Operating system:
PHP version: Next Minor Version
Package: PHP Language Specification
Bug Type: Feature/Change Request
Bug description:FR: support to new() keyword
Description:
------------
It should works exactly like the `new`, but with some features.
// Usage.
new('\User'); === new User;
new(User::class); === new User;
new($user); === new $user;
$user = new(User::class)->find(1); === (new User)->find(1);
// Arguments.
new(User::class, 1, 2, 3) === new User(1, 2, 3);
// Maybe: use another object to copy directly the name.
$userClass = new(User::class);
$userNew = new($userClass); === $userNew =
new(get_class($userClass));
Signature (pseudo-code):
function new ($object, ... $args) {
assert(is_object($object) || is_string($object));
assert(!is_resource($object));
if (is_object($object)) {
$objectClass = get_class($object);
return new $objectClass(... $args);
}
return new $object(... $args);
}
--
Edit bug report at https://bugs.php.net/bug.php?id=70413&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70413&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70413&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70413&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70413&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70413&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70413&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70413&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70413&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70413&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70413&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70413&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70413&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70413&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70413&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70413&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70413&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70413&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70413&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70413&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70413&r=mysqlcfg