Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104376 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 31794 invoked from network); 13 Feb 2019 11:18:25 -0000 Received: from unknown (HELO mail-qt1-f175.google.com) (209.85.160.175) by pb1.pair.com with SMTP; 13 Feb 2019 11:18:25 -0000 Received: by mail-qt1-f175.google.com with SMTP id z39so1608430qtz.0 for ; Wed, 13 Feb 2019 00:01:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=8qn5QvBLgI2bEFCk4HO57sEFkPP5Nxxkr+MGP4xLbv4=; b=Nck1eNTib3tA0hcipgU6FmX2NJ1VIssmEhShVp1QSk/0sgWfs0xBlafQThJF71c4HE QR3BJKd930+JIVjkZokeG0xx9Pih4FdyN2BF1Z2u/qXiltIduIDR6XZ2XK53QTj4gi8K GDwSXOX/oxnJKMmps6pwEwdTXSIUe0zRzJ/KaNGImiRnzm0MZLH3hv0KqU7ZudicqO3i 2JDZVa9UlkRL2G7Ulgo+5n9UfWtbBsSq1/kIoC/KGT+7asHbkCrjufWp+Qssw6aL65y+ iq7uRIHuLcoukSx4DQEhPI8LXKYZdxF/lpPzSedPMYQFPDYyMl7S0feNJGu44IY4D2Fn wKlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=8qn5QvBLgI2bEFCk4HO57sEFkPP5Nxxkr+MGP4xLbv4=; b=eZeA2rhRi94zsW4fy1vxUFlZcKBJB0cp+lXxHzKcZ/f9BHC4EWCPe+eXo48Tu5tl+h nu16nXzR1ErS4mSKvWzX1j//CaSYhSxHBfKiQZJf4OlJKi0mAdXAi7WIqBsUJ9CjjZig zwRESpoLCA/kfEbtxbWLyqCag5YD8+FOOg2R77TR3mdRUDkSlZ4QBUmaTBYsUBjSJQRQ TVTIDnYoq7ikSXumICxqGfrwALZjIIrvxq38b00E5bLHmwqL+b4+0CmdBKr0OC4pWx7j qlKsOKWY/TBBSEWNlxQBeMCvSohKvZhSFKglSBSr5MSmRrFRoMxRUxJ4rwp2OCbRgJ8z rJMQ== X-Gm-Message-State: AHQUAuZmFfi7gBIW59mbDIrgTu0Up9gkybOL9MbiN8xTtli0D67FqmJf GgoIAhwneCcC4Tgb+dugvojRzP6oxxeDql5EFnjOqNPpCIw= X-Google-Smtp-Source: AHgI3IbV8U+2mI6d4sx45ldgtrxaBJScD9oIN0QuDFf475PQulr4n2ashmvqLYKjD7yIZsrIqR9FQp/8MWYtEE/zoDg= X-Received: by 2002:ac8:2e16:: with SMTP id r22mr6062531qta.384.1550044889409; Wed, 13 Feb 2019 00:01:29 -0800 (PST) MIME-Version: 1.0 Date: Wed, 13 Feb 2019 09:01:21 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="00000000000004ffae0581c1f3ac" Subject: proper anonymous classes? From: rasmus@mindplay.dk (Rasmus Schultz) --00000000000004ffae0581c1f3ac Content-Type: text/plain; charset="UTF-8" The fact that the anonymous class syntax defines a class *and* immediately constructs an instance is quite annoying. For one, this is quite incompatible with DI containers' ability to resolve constructor arguments. Lets say you DI container can register a named component by merely referencing a class that uses constructor injection - so lets say this works: class MyController { public function __construct(MyService $service) { // ... } } $container->register("my-controller", MyController::class); Now I want to register an anonymous class, for example as part of an integration test-suite, which is common enough: $container->register("my-controller", new class { public function __construct(MyService $service) { // ... } }); This doesn't work, because you're expected to actually pass the constructor arguments immediately - because you can only define an anonymous class while immediately creating an instance. What I really want is just an anonymous class - not an instance, so: $container->register("my-controller", class { public function __construct(MyService $service) { // ... } }); The question is, what would a class expression without the new keyword evaluate to? Since we normally reference classes with just a class-name, I guess I'd expect a string, like you'd get from the ::class constant. Any hope for something like that? --00000000000004ffae0581c1f3ac--