Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91424 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24302 invoked from network); 25 Feb 2016 22:11:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2016 22:11:20 -0000 Authentication-Results: pb1.pair.com header.from=danack@basereality.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=danack@basereality.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basereality.com from 209.85.161.176 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.161.176 mail-yw0-f176.google.com Received: from [209.85.161.176] ([209.85.161.176:36079] helo=mail-yw0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AF/E7-11730-70C7FC65 for ; Thu, 25 Feb 2016 17:11:20 -0500 Received: by mail-yw0-f176.google.com with SMTP id e63so54619001ywc.3 for ; Thu, 25 Feb 2016 14:11:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=2w67Ad/hGMoe/3BlIGLZ+LY4D0OAmSU+BP87mg7AI94=; b=q2Qv/HvE5AqVxzi2YdCp4r6ZuQu5PZ6pWOq5pmcnksZDhk1qJQIvPto8yY1jYYsmwk JtkDOJGXJH3m3TIM1Q9BYRB4hK+LMExrRAX/4ZwMxRZlV5mY9nEXnxgiPk+GGWyAw6ML bgWDd/NjRap5anzGD3TcgNEuY+RhMqFIzfhT1a2KakAMPpqeAMjMyjUEhsJ9mB523RoF DthdBUlGvpA3gaR3t7Xb6qnBqS7Fw6eSK/o761Vvx6O6Q6tvvhtGo0XQl0T617un0GUN ewK4dKHSFfG58vnMFt5vPfb0hjnBRi1vHuFGogCG319tUjiAMF3lZxvhxORg01pz6W7L vHvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=2w67Ad/hGMoe/3BlIGLZ+LY4D0OAmSU+BP87mg7AI94=; b=C5Mx3cbpz+LABdVSYBYePiZ4xkKlcWVGvcyrW4yPV19pOCn/4Ay6gvwITPTypPnjP6 ghzVbUB+xms6cb9fWZLud13oOVVOfFB40GCwQCpsIAKGypKkA6TFfVpmkh3qF8Ai2s65 cL5a0Ofg20XJMTDKf1aJJIawuGlwXM21jsg1tF8fjVO1pWkZ61+2qlExqamsLW+UVOec +3XIQ4Fy7722816sd2IcPSUWUVN5RnOjXBVfIVlb4m80lekJcr3GLtyXRirliDfevzlU 72QgXlKll0S9OHG5sass1iug4qmCDZ9KpP161qqdSHp9330lNQDOM6FVY66tpR0W2YZO vyUA== X-Gm-Message-State: AG10YOSZNm9CZFkzLI3lLotJc08SSSwiUJO+ZRB5njL8jxUsM9+rXeldGfGiR9mcL1qhm90u2mt+uvntCIVGgA== MIME-Version: 1.0 X-Received: by 10.129.135.7 with SMTP id x7mr23825324ywf.95.1456438276154; Thu, 25 Feb 2016 14:11:16 -0800 (PST) Received: by 10.37.43.85 with HTTP; Thu, 25 Feb 2016 14:11:16 -0800 (PST) X-Originating-IP: [2.98.210.180] In-Reply-To: References: Date: Thu, 25 Feb 2016 22:11:16 +0000 Message-ID: To: Ryan Pallas Cc: Marco Pivetta , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Callable constructors From: danack@basereality.com (Dan Ackroyd) On 25 February 2016 at 18:32, Ryan Pallas wrote: > If fetchAll is coming from PDO. then you could have simply done this: > > $records = $db->someQuery()->fetchAll(MyRecord::class); That is a great argument as to why constructors should be callable without using the 'new'. It's been possible to do that in PDO for years, and people have been using it, and liking it, even if they weren't aware that 'under the hood' the PDO extension was doing the equivalent of calling 'new' as a callable. But why is it restricted to PDO? Why can't I do the equivalent with other DB libraries of my choice? Why can't I use it with userland libraries that retrieve data from Redis, Mongo or any other datasource? It has shown to be a useful pattern inside PDO. We should be empowering userland developers to have the same tools available to them as extensions do, wherever possible. This RFC would allow the equivalent of PDO::FETCH_CLASS to be implemented by userland code. Which sounds great to me. > Moreover, if you want to pass in a callable that creates the class, why not > just create a method on that class called create (or whatever) much the > same way that singletons often work. Why should every PHP developer have to jump through that hoop, why can't we (as the RFC proposes) make constructors be callable, instead of having to create another method just to call something that should have been callable in the first place? And to be precise, people need to use code that was either written outside their organisation, or within their organisation but in another department. In either case it wouldn't be possible to alter the code just to make it callable in a certain way. And so it would be easier if the language just supported something that could have been supported right from the start. cheers Dan