LinksUpdate uses SELECT FOR UPDATE, thus starting a new transaction. So we have to...
[mediawiki.git] / PHPTAL-NP-0.7.0 / libs / Types / Ref.php
blob0f81dc762d54b423d88f5098202d08cde025363b
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
3 //
4 // Copyright (c) 2003 Laurent Bedubourg
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // Authors: Laurent Bedubourg <laurent.bedubourg@free.fr>
21 //
23 /**
24 * Create a new Ref object referencing specified object or variable.
26 * Any modification of the source object modify the Refence content, any
27 * modification of the reference obj modify the source object.
29 * The referenced object can be reached using the reference object using the
30 * 'obj' property.
32 * <?php
34 * $a = new Foo();
35 * $ref_a = Ref($a);
37 * $ref_a->obj->doBar(); // call doBar() on $a
39 * ?>
41 * @param mixed $obj -- the object or variable to reference.
42 * @return Ref
44 function ref(&$obj)
46 return new Ref($obj);
49 /**
50 * Returns true if the object is a Ref object.
52 * @param mixed $obj -- any variable that must be tested.
54 * @return boolean
56 function is_ref($obj)
58 return is_object($obj) && get_class($obj) == "ref";
62 /**
63 * Reference class.
65 * There's a lot to say about references in PHP. The main problem come from the
66 * fact that until ZendEngine2, objects are copied if not referenced.
68 * This class helps keeping references to objects even while modifying arrays.
70 * Example :
72 * If an array stores objects, using array_values will copy its
73 * elements.
75 * If an array stores Ref objects referencing real objects, array_values copy
76 * Ref objects but these copies still reference the source object.
78 * Until ZendEngine2, it is safer to use Ref objects in stead of object
79 * references.
81 * <?php
83 * $a = new Foo('bar');
84 * $v = new Vector();
85 * $v->push(Ref($a));
87 * ?>
89 * Important :
91 * This object will have no meaning in php 4.4 as PHP will then use references
92 * everywhere objects are involved.
94 * @author Laurent Bedubourg <laurent.bedubourg@free.fr>
96 class Ref
98 /**
99 * php reference to data.
101 var $obj;
104 * Reference constructor.
106 * Important:
108 * If $r is a reference, the new reference will just be a copy of the
109 * parameter.
111 * A Ref cannot reference a Ref.
113 * @param mixed $r -- the object or data to reference.
115 function Ref(&$r)
117 if (is_ref($r)) {
118 $this->obj =& $r->obj;
119 } else {
120 $this->obj =& $r;
125 * Retrieve the type or the referenced variable.
127 * @return string
129 function type()
131 return gettype($this->obj);
135 * Return the class name of the referenced variable (if object).
137 * @return string (empty if not an object)
139 function getClassName()
141 return get_class($this->obj);