Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:33379 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75804 invoked by uid 1010); 22 Nov 2007 20:40:50 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 75789 invoked from network); 22 Nov 2007 20:40:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Nov 2007 20:40:50 -0000 Authentication-Results: pb1.pair.com header.from=marco.kaiser@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=marco.kaiser@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 64.233.170.185 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: marco.kaiser@gmail.com X-Host-Fingerprint: 64.233.170.185 rn-out-0910.google.com Linux 2.4/2.6 Received: from [64.233.170.185] ([64.233.170.185:38328] helo=rn-out-0102.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AE/78-19690-159E5474 for ; Thu, 22 Nov 2007 15:40:50 -0500 Received: by rn-out-0102.google.com with SMTP id s28so945818rnb for ; Thu, 22 Nov 2007 12:40:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=kLcKVAUjQusrjGQM4or7uVtLlQ5cJd9RDXfmz0AumLs=; b=QqGxjcTxJwbaVtvtsXU/j/1Ditdcg/leuZG6ZvVrx0VHq87CBVv0jbYw6XH+vJw11vg+ovsHfPUZS2KnBcaMIujaf3+pbKgn9jM9m1lj95x+4Qv0NWwC1S2cEqx+wmQZwIu0d32nPDp3ETYWNbiRki9igQ2QA5zRHvfqOdEq/Ak= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=CWlvTn7zPUg9I2NLdcJkwtBgEfp/kEECn0BbfhBXNgrTrsVNa61A+jxZayqNSC2WspDpOfZVGK/QeA/ulnh7fvdy6BMWaM9KOIaW7DtJXooGZVVs8jZaTyE8S/Yp3cx2LDNIkiKyiNSYgg/soUNv6FjJrkvJ3XSRaU4aCifMfL8= Received: by 10.151.13.7 with SMTP id q7mr1780568ybi.1195764047218; Thu, 22 Nov 2007 12:40:47 -0800 (PST) Received: by 10.150.123.19 with HTTP; Thu, 22 Nov 2007 12:40:47 -0800 (PST) Message-ID: Date: Thu, 22 Nov 2007 21:40:47 +0100 To: "PHP Developers Mailing List" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <4740C654.3020302@digitalsandwich.com> <47417C65.8010708@iamjochem.com> <474130B3.9070303@digitalsandwich.com> <4741DC81.6000506@zend.com> <4741D574.2020800@digitalsandwich.com> <474247A2.5050301@zend.com> <4741D9D1.6030106@digitalsandwich.com> <47424B4F.2@zend.com> <4743CED7.5050402@avalon.aut.bme.hu> Subject: Re: [PHP-DEV] late static binding php6 From: marco.kaiser@gmail.com ("Marco Kaiser") Hi again, to explain the main idea a bit more, the code below work and moves the main getInstance function from the class and its possible to abstract this. it would be cool to get the protected property also into the abstract class. Any idea or maybe a solution in the near future? On Nov 22, 2007 9:29 PM, Marco Kaiser wrote: > Hi List, > > just to drop my note here, i asked (i think) 2 years ago for such a > feature to automate my singleton pattern. Not with late static > bindings this is possible. > > class singleton > { > static protected $_instance = null; > > static public function getInstance() > { > $caller = get_called_class(); > if (!static::$_instance instanceof $caller) { > static::$_instance = new $caller; > } > > return static::$_instance; > } > } > > class foo extends singleton > { > } > > var_dump(foo::getInstance()); > var_dump(foo::getInstance()); > ?> > > i think this will also drop much redundant code from some frameworks. :) > So this is one of my examples that helps much. > > > -- > Marco Kaiser > -- Marco Kaiser