curt            Wed Feb  2 22:02:56 2005 EDT

  Modified files:              
    /phpdoc/en/language/oop5    patterns.xml 
  Log:
  incorporate note, to prevent clone'ing of singletons
  
  
http://cvs.php.net/diff.php/phpdoc/en/language/oop5/patterns.xml?r1=1.5&r2=1.6&ty=u
Index: phpdoc/en/language/oop5/patterns.xml
diff -u phpdoc/en/language/oop5/patterns.xml:1.5 
phpdoc/en/language/oop5/patterns.xml:1.6
--- phpdoc/en/language/oop5/patterns.xml:1.5    Wed Feb  2 21:51:07 2005
+++ phpdoc/en/language/oop5/patterns.xml        Wed Feb  2 22:02:56 2005
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.5 $ -->
+<!-- $Revision: 1.6 $ -->
 <sect1 id="language.oop5.patterns">
  <title>Patterns</title>
  <para>
@@ -74,7 +74,7 @@
     // Hold an instance of the class
     private static $instance;
     
-    // A private constructor
+    // A private constructor; prevents direct creation of object
     private function __construct() 
     {
         echo 'I am constructed';
@@ -96,6 +96,13 @@
     {
         echo 'Woof!';
     }
+
+    // Prevent users to clone the instance
+    public function __clone()
+    {
+        trigger_error('Clone is not allowed.', E_USER_ERROR);
+    }
+
 }
 
 ?>
@@ -115,6 +122,9 @@
 $test = Example::singleton();
 $test->bark();
 
+// This will issue an E_USER_ERROR.
+$test_clone = clone($test);
+
 ?>
 ]]>
    </programlisting>

Reply via email to