incorporate note, to prevent clone'ing of singletons

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@178767 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Curt Zirzow 2005-02-03 03:02:56 +00:00
parent 118db453ef
commit 1f2d15aca6

View file

@ -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 @@ class Example
// 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 @@ class Example
{
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 = new Example;
$test = Example::singleton();
$test->bark();
// This will issue an E_USER_ERROR.
$test_clone = clone($test);
?>
]]>
</programlisting>