Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84113 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49216 invoked from network); 1 Mar 2015 19:04:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Mar 2015 19:04:24 -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.160.178 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.160.178 mail-yk0-f178.google.com Received: from [209.85.160.178] ([209.85.160.178:36053] helo=mail-yk0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F4/E0-42670-7B263F45 for ; Sun, 01 Mar 2015 14:04:24 -0500 Received: by ykp131 with SMTP id 131so11536271ykp.3 for ; Sun, 01 Mar 2015 11:04:20 -0800 (PST) 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=9+W8DjYSdLOiy2dHRFdc4cQztWMCisJW+W0C8sjbrag=; b=OoDLwqc3Q3+x5e5EmIvxlvyT9bAFRlhREhytQGRcAEz3m17tUz6x2bjpf5ZPCGfiZZ mldD0DhLpqjfbBfkqacRc90dtIl0mKmZQZVB7VpwKj3F8ETqk9SDnpF6/2q+paAbL/QN +aoiUAn6hv/D1/fYOaD5TxtClYLd8b9Rezk0qme6AcZbbN+AkW/wZk2luIMchb4KLp0q L0ziuzuVWP0KK9IAqecWGlePTKN5ENuntU7SlSs6ZKFOuOcDrfvIxuvHnzcr2dUxmD7p ZD6VB/yOQb0fVgEnjs2RkcKCp+wN/LXo+3b2BHwFrw2uzwQD/wtbHU4IEoREQuo0N8J1 WMog== X-Gm-Message-State: ALoCoQkpY+P9L745Z42eqF2mGJiiBUASIlAc2SoZBtsk+JFOZ4vUEGxa0Z9tkOsbd4bembsMYART MIME-Version: 1.0 X-Received: by 10.170.100.87 with SMTP id r84mr24360874yka.73.1425236660253; Sun, 01 Mar 2015 11:04:20 -0800 (PST) Received: by 10.170.71.86 with HTTP; Sun, 1 Mar 2015 11:04:20 -0800 (PST) X-Originating-IP: [2.96.87.154] In-Reply-To: <54F35C0F.4090905@mabe.berlin> References: <54F35C0F.4090905@mabe.berlin> Date: Sun, 1 Mar 2015 19:04:20 +0000 Message-ID: To: Marc Bennewitz Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC][DISCUSSION] Constructor behaviour of internal classes From: danack@basereality.com (Dan Ackroyd) On 1 March 2015 at 18:35, Marc Bennewitz wrote: > What are the reasons to not make this class instantiable / extendable ? That class handles database state / resources that are not exposed through the userland classes. It's correct in my opinion for it to not be extendible or instantiable. Obviously it would be awesome if they were covered by an interface, to allow testign to be easier, but that's a separate issue. > That's definitely better but it's an behavior not possible to implemented in > user land code as it would be impossible to get such an object. The same behaviour can seen with the code below. cheers Dan class Foo { private static $internalConstruction = false; public function __construct() { $constructionAllowed = !self::$internalConstruction; self::$internalConstruction = false; if ($constructionAllowed == false) { throw new \Exception("External construction not allowed"); } } public static function create() { self::$internalConstruction = true; return new self(); } } $foo = Foo::create(); var_dump($foo); $bar = new Foo();