Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104377 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 35944 invoked from network); 13 Feb 2019 11:33:20 -0000 Received: from unknown (HELO mail-wr1-f51.google.com) (209.85.221.51) by pb1.pair.com with SMTP; 13 Feb 2019 11:33:20 -0000 Received: by mail-wr1-f51.google.com with SMTP id f14so1431889wrg.1 for ; Wed, 13 Feb 2019 00:16:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=b5XRMtwCw2fGHgdVpeZiAwa5G9hqN0mbHUtzhgURKY8=; b=iAapUzCo0/QIBzIeoVvdwrIb/VeK1C4pr3DXTTKJSQIW2UDkT92aAXBH8H4saQtI5v f2Mfu9xddQQlQCG3YP9VWGVtqhceny89I5x8rLJnAD8c1Q6tqoXXA9ImmPnp19TS/IgP 4Az9QPqQsZMyJqdBYIaUFiLsA96Or8pCp0mCzKWJ6OfOxtr8JIYNkRs/dy1c1UFKRLHC juhc21AFaie9EzuOWVDPsjT3VL2MbwKbOKCU7X1cgjT0N1arywTh2tAhRr3c3I9/lOUU GKKt9It8n3kf4hnhj+mXXKujtLUxl7mO5RJ+7KvqQXn8+TP2AF5mDP6VFpl7AwF3W3S7 n5eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=b5XRMtwCw2fGHgdVpeZiAwa5G9hqN0mbHUtzhgURKY8=; b=jxiC4JixeO4+D61poDOzvWmnAdGsoztBxf+phWxLo6+8YD+/vx2GhH2y1ZEqYplSof i2ksjBed5gwBhoH8+Q7wm/wU3qHNi9IrufvI2hob20fYWSjascvI+OnCheFd2D5ytUh1 TcjkxdowFATBZW0Lndfz2dw1pBBsBzojpKQ15uwlnppO967AkUEA9YFhJ+skGCSG1ehY UK+D4s3yqz4Bqv7hsR9yTwSXxX+kiExy9OeofNA9p4JLhbUzJ4+vYrivCStWhyzDPUop ivzq9E/c7EkNGP5IKsKHDmBE2JH+//mqIRItnhQiTlQXlMbzWI4Zj/cFlJ9hOSUVSBqW eRoA== X-Gm-Message-State: AHQUAubhTRgdTUPodQWX4jWR2LpyGQH9UWwXpNOGUMUWRzYzvL2ugvJT oqagmIQ2MXHYBq+J+l3XGm+ae3zND8xpiebfawU= X-Google-Smtp-Source: AHgI3IZ6SouFLwsi5/HVSp2z4mrUdS454s/iz4bGR7rZgdnVHGjLCmSDbToWksj9jk2UNSgt0Ts3Osa+FPS3x+uJm/c= X-Received: by 2002:a5d:6041:: with SMTP id j1mr5810081wrt.297.1550045785226; Wed, 13 Feb 2019 00:16:25 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 13 Feb 2019 09:16:13 +0100 Message-ID: To: Rasmus Schultz Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000006a041c0581c22884" Subject: Re: [PHP-DEV] proper anonymous classes? From: krakjoe@gmail.com (Joe Watkins) --0000000000006a041c0581c22884 Content-Type: text/plain; charset="UTF-8" What you describe is first class support for classes, nothing much to do with anonymous classes. On Wed, 13 Feb 2019, 09:01 Rasmus Schultz 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? > --0000000000006a041c0581c22884--