note 91879 added to language.oop5.patterns

From: Date: Tue, 30 Jun 2009 16:56:40 +0000
Subject: note 91879 added to language.oop5.patterns
Groups: php.notes 
Request: Send a blank email to php-notes+get-157706@lists.php.net to get a copy of this message
rskret's code below doesn't make any sense - if you move the return line as he says you will only ever get one instance back from the singleton() method, and subsequent calls will return nothing. Almost definitely not what you want. Consider the following code <?php $connection = DB::singleton(); $connection->exec('DROP TABLE foo'); drop_bar(); $connection->exec('DROP TABLE baz'); function bar() { $connection = DB::singleton(); $connection->exec('DROP TABLE bar'); } ?> You don't want 2 connections to the database, that would be slow and wasteful. So, you're DB classes uses a singleton() method to return the same connection every time. If it returned nothing (like rskret's code does) it would be useless to you. ---- Server IP: 209.41.74.194 Probable Submitter: 66.169.84.158 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.patterns.php Edit -- https://master.php.net/note/edit/91879 Del: integrated -- https://master.php.net/note/delete/91879/integrated Del: useless -- https://master.php.net/note/delete/91879/useless Del: bad code -- https://master.php.net/note/delete/91879/bad+code Del: spam -- https://master.php.net/note/delete/91879/spam Del: non-english -- https://master.php.net/note/delete/91879/non-english Del: in docs -- https://master.php.net/note/delete/91879/in+docs Del: other reasons-- https://master.php.net/note/delete/91879 Reject -- https://master.php.net/note/reject/91879 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157706) next »