tgoop.com/phpyh/481
Create:
Last Update:
Last Update:
📝 new MyClass()->method() без скобок
В конце прошлого года я придумал правку для синтаксиса PHP, которая позволит не оборачивать new
выражения в cкобки для обращения к ним:
final class MyClass
{
const CONSTANT = 'constant';
public static $staticProperty = 'staticProperty';
public static function staticMethod(): string { return 'staticMethod'; }
public $property = 'property';
public function method(): string { return 'method'; }
public function __invoke(): string { return '__invoke'; }
}
var_dump(
new MyClass()::CONSTANT, // string(8) "constant"
new MyClass()::$staticProperty, // string(14) "staticProperty"
new MyClass()::staticMethod(), // string(12) "staticMethod"
new MyClass()->property, // string(8) "property"
new MyClass()->method(), // string(6) "method"
new MyClass()(), // string(8) "__invoke"
);
Только что я наконец-то опубликовал RFC через internals! В течение как минимум двух недель будет проходить обсуждение, потом открою голосование.
RFC: https://wiki.php.net/rfc/new_without_parentheses
Реализация и тесты: https://github.com/php/php-src/pull/13029
Можно следить за обсуждением на сайте, а можно подписаться на рассылку и принять в нём участие.
BY Пых
Share with your friend now:
tgoop.com/phpyh/481