Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91442 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64188 invoked from network); 27 Feb 2016 18:56:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Feb 2016 18:56:19 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.66 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.66 mail-wm0-f66.google.com Received: from [74.125.82.66] ([74.125.82.66:36614] helo=mail-wm0-f66.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DB/B9-55238-151F1D65 for ; Sat, 27 Feb 2016 13:56:17 -0500 Received: by mail-wm0-f66.google.com with SMTP id l68so1850187wml.3 for ; Sat, 27 Feb 2016 10:56:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=gSkgzgtffl0fFLhuVMEPrJ56MZKe2MFfL4L1j/d+xlk=; b=h/+TIjhQ4WbAXMX5W6QNNNGcMWz4rNeXBXvWq/rPrrk0GxMF7aHg36xNboJR12HfEf rU/yXnzU7WTPFciQ4U9Qkong8HwQhtIZUJaMjjmvCvlmLAU9U6rISZaPNU1gkt1rdnP4 hJwJJPQ9wiaTFyZRRxXds4OoJ/yptLC9v1fnwuvUaC2zfDbpca3OgVtTM5E8HkarLX7E WPubxLgdJ6cAqkNC00iTFiyJKMxoVeZsfan3a45AuH9YY0Ztl8oMnk+swjtpE9g7Sz89 c9AZOdPlpJ8qjNzvLf3hTvWqVeWQ1sC+TNsBB0sKWz5TWWV/GWgkpCvuTgeohEAKJUrC 5wag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=gSkgzgtffl0fFLhuVMEPrJ56MZKe2MFfL4L1j/d+xlk=; b=hrfmgb/1QWRVuMsIOPMOpXx/Pk/E0B2ZpouxiugHtSqrrf9KGtHrnL7lW1+oWy5B/p PX/eTgkgcBqvZ6RycElqS3HUe83RCaMF77GIFRgiQSk5lg6a/pMJz46bnialjwuTjBf2 3QXKnTBm71AaXVaftTy8Unqz4oG5ubmyR+jjgsnlYw+Beg3BIgAbN+Ciw3iar76IX4x0 iGTl/MFdpa8AE79vMncl74hZu0FidKHLntxqQUAMXB9zSFIdx1KojYsizwfs0XqeJVai 5cimjxt3TXR0WmPAoCLdSjwi1OA9tCdq/+KJyCnSme7fLeP+sV9YwpHMcP4td25zlQn9 xUcg== X-Gm-Message-State: AD7BkJIyNwZhv8SFQLZOHoSVOIYL/clXM8bdblRIRlDTXkLw6ZMn9Uc7kJyZVOLj56vL5w== X-Received: by 10.28.109.141 with SMTP id b13mr3627574wmi.25.1456599374856; Sat, 27 Feb 2016 10:56:14 -0800 (PST) Received: from [192.168.1.189] ([95.148.161.211]) by smtp.googlemail.com with ESMTPSA id 82sm7312602wmd.4.2016.02.27.10.56.13 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 27 Feb 2016 10:56:13 -0800 (PST) To: Dan Ackroyd , Adam Harvey References: Cc: "internals@lists.php.net" Message-ID: <56D1F144.7070202@gmail.com> Date: Sat, 27 Feb 2016 18:56:04 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Callable constructors From: rowan.collins@gmail.com (Rowan Collins) On 26/02/2016 17:08, Dan Ackroyd wrote: > Rowan Wrote: >> I would like to join Adam in asking if >> you can find examples in other languages where constructors can be used >> as though they were static methods in this way. > Python would be a good example. constructors are just functions that > can be called, and passed around as 'callable' things. > > Obviously Pythons concepts of classes aren't identical to PHP' > concepts - but the code is doing the same thing; passing around a > thing that can be called without having to use Reflection to make it a > callable. > > > http://goo.gl/SnTNZH Looking at your example at first, I couldn't see how it demonstrated any such passing, because you can dynamically select class names in PHP (here's that code transposed line-by-line to PHP): https://3v4l.org/AD2m3 Looking closer, that's not actually what's happening, but it's still not equivalent to what you want in PHP: - The first difference is that "Foo()" rather than "new Foo()" creates an object; the fact that "Foo" is a class rather than a function causes this to happen when it is invoked. This is different from PHP, where classes and functions don't share a namespace, and a class is not something that can be invoked ("foo()" doesn't refer to the same thing as "new foo()"). - The second difference is that you are not passing around a string representing what to call, but a reference to the invokable object itself. The line "classname = Foo" simply makes "classname" an alias for the class "Foo", which is then invokable as before to trigger instantiation. So if anything, this particular example is more like my Callable::forConstructor() idea - a way of passing around an invokable object which, when invoked, will cause instantiation of a particular class. I don't, however, know Python well enough to say whether a better example would be more like what you want in PHP. Regards, -- Rowan Collins [IMSoP]