aidan Sat Oct 2 05:40:56 2004 EDT
Modified files:
/phpdoc/en/language/oop5 abstract.xml autoload.xml basic.xml
cloning.xml constants.xml exceptions.xml
iterations.xml magic.xml
object-comparison.xml overloading.xml
paamayim-nekudotayim.xml reflection.xml
static.xml
Log:
Applied PEAR coding standards to examples
http://cvs.php.net/diff.php/phpdoc/en/language/oop5/abstract.xml?r1=1.7&r2=1.8&ty=u
Index: phpdoc/en/language/oop5/abstract.xml
diff -u phpdoc/en/language/oop5/abstract.xml:1.7
phpdoc/en/language/oop5/abstract.xml:1.8
--- phpdoc/en/language/oop5/abstract.xml:1.7 Thu Aug 26 06:15:38 2004
+++ phpdoc/en/language/oop5/abstract.xml Sat Oct 2 05:40:49 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.7 $ -->
+<!-- $Revision: 1.8 $ -->
<sect1 id="language.oop5.abstract">
<title>Object Abstraction</title>
@@ -23,32 +23,29 @@
<programlisting role="php">
<![CDATA[
<?php
-
-abstract class AbstractClass {
-
- /* Force Extending class to define this method */
- abstract protected function getValue();
-
- /* Common method */
- public function printOut() {
- print $this->getValue();
- }
-
+abstract class AbstractClass
+{
+ // Force Extending class to define this method
+ abstract protected function getValue();
+
+ // Common method
+ public function printOut() {
+ print $this->getValue();
+ }
}
-class ConcreteClass1 extends AbstractClass {
-
- protected function getValue() {
- return "ConcreteClass1";
- }
-
+class ConcreteClass1 extends AbstractClass
+{
+ protected function getValue() {
+ return "ConcreteClass1";
+ }
}
-class ConcreteClass2 extends AbstractClass {
-
- protected function getValue() {
- return "ConcreteClass2";
- }
+class ConcreteClass2 extends AbstractClass
+{
+ protected function getValue() {
+ return "ConcreteClass2";
+ }
}
http://cvs.php.net/diff.php/phpdoc/en/language/oop5/autoload.xml?r1=1.1&r2=1.2&ty=u
Index: phpdoc/en/language/oop5/autoload.xml
diff -u phpdoc/en/language/oop5/autoload.xml:1.1
phpdoc/en/language/oop5/autoload.xml:1.2
--- phpdoc/en/language/oop5/autoload.xml:1.1 Sat Sep 25 05:10:50 2004
+++ phpdoc/en/language/oop5/autoload.xml Sat Oct 2 05:40:50 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.1 $ -->
+<!-- $Revision: 1.2 $ -->
<sect1 id="language.oop5.autoload">
<title>Autoloading Objects</title>
<para>
@@ -26,8 +26,7 @@
<programlisting role="php">
<![CDATA[
<?php
-function __autoload($class_name)
-{
+function __autoload($class_name) {
include_once($class_name . 'php');
}
http://cvs.php.net/diff.php/phpdoc/en/language/oop5/basic.xml?r1=1.4&r2=1.5&ty=u
Index: phpdoc/en/language/oop5/basic.xml
diff -u phpdoc/en/language/oop5/basic.xml:1.4 phpdoc/en/language/oop5/basic.xml:1.5
--- phpdoc/en/language/oop5/basic.xml:1.4 Thu Aug 26 16:21:33 2004
+++ phpdoc/en/language/oop5/basic.xml Sat Oct 2 05:40:50 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.4 $ -->
+<!-- $Revision: 1.5 $ -->
<sect1 id="language.oop5.basic">
<title>The Basics</title>
@@ -21,14 +21,15 @@
<programlisting role="php">
<![CDATA[
<?php
-class SimpleClass {
- /* member declaration */
- public $var = 'a default value';
-
- /* method declaration */
- public function displayVar() {
- echo $this->var; /* Echo my own $var value */
- }
+class SimpleClass
+{
+ // member declaration
+ public $var = 'a default value';
+
+ // method declaration
+ public function displayVar() {
+ echo $this->var;
+ }
}
?>
]]>
@@ -70,11 +71,9 @@
$assigned = $instance;
$reference =& $instance;
-
$instance->var = '$assigned will have this value';
-$instance = null; /* $instance and $reference become null */
-
+$instance = null; // $instance and $reference become null
var_dump($instance);
var_dump($reference);
@@ -116,13 +115,14 @@
<programlisting role="php">
<![CDATA[
<?php
-class ExtendClass extends SimpleClass {
-
- /* Redefine the parent method */
- function displayVar() {
- echo "Extending class\n";
- parent::displayVar();
- }
+class ExtendClass extends SimpleClass
+{
+ // Redefine the parent method
+ function displayVar()
+ {
+ echo "Extending class\n";
+ parent::displayVar();
+ }
}
$extended = new ExtendClass();
http://cvs.php.net/diff.php/phpdoc/en/language/oop5/cloning.xml?r1=1.3&r2=1.4&ty=u
Index: phpdoc/en/language/oop5/cloning.xml
diff -u phpdoc/en/language/oop5/cloning.xml:1.3 phpdoc/en/language/oop5/cloning.xml:1.4
--- phpdoc/en/language/oop5/cloning.xml:1.3 Sat Aug 7 13:39:27 2004
+++ phpdoc/en/language/oop5/cloning.xml Sat Oct 2 05:40:50 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.3 $ -->
+<!-- $Revision: 1.4 $ -->
<sect1 id="language.oop5.cloning">
<title>Object cloning</title>
@@ -30,13 +30,11 @@
</informalexample>
<para>
-
When an object is cloned, PHP 5 will perform a shallow copy of all of the
object's properties. Any properties that are references to other variables,
will remain references. If a __clone() method is defined, then the newly
created object's __clone() method will be called, to allow any necessary
properties that need to be changed.
-
</para>
<example>
@@ -44,31 +42,31 @@
<programlisting role="php">
<![CDATA[
<?php
-
-class SubObject {
- static $instances = 0;
- public $instance;
-
- public function __construct() {
- $this->instance = ++self::$instances;
- }
-
- public function __clone() {
- $this->instance = ++self::$instances;
- }
+class SubObject
+{
+ static $instances = 0;
+ public $instance;
+
+ public function __construct() {
+ $this->instance = ++self::$instances;
+ }
+
+ public function __clone() {
+ $this->instance = ++self::$instances;
+ }
}
-class MyCloneable {
-
- public $object1;
- public $object2;
-
- function __clone() {
-
- // Force a copy of this->object, otherwise
- // it will point to same object.
- $this->object1 = clone($this->object1);
- }
+class MyCloneable
+{
+ public $object1;
+ public $object2;
+
+ function __clone()
+ {
+ // Force a copy of this->object, otherwise
+ // it will point to same object.
+ $this->object1 = clone($this->object1);
+ }
}
$obj = new MyCloneable();
http://cvs.php.net/diff.php/phpdoc/en/language/oop5/constants.xml?r1=1.4&r2=1.5&ty=u
Index: phpdoc/en/language/oop5/constants.xml
diff -u phpdoc/en/language/oop5/constants.xml:1.4
phpdoc/en/language/oop5/constants.xml:1.5
--- phpdoc/en/language/oop5/constants.xml:1.4 Sat Aug 7 14:05:14 2004
+++ phpdoc/en/language/oop5/constants.xml Sat Oct 2 05:40:50 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.4 $ -->
+<!-- $Revision: 1.5 $ -->
<sect1 id="language.oop5.constants">
<title>Object Constants</title>
<para>
@@ -15,19 +15,20 @@
<programlisting role="php">
<![CDATA[
<?php
-class MyClass {
- const constant = 'constant value';
+class MyClass
+{
+ const constant = 'constant value';
- function showConstant() {
- echo self::constant . "\n";
- }
+ function showConstant() {
+ echo self::constant . "\n";
+ }
}
echo MyClass::constant . "\n";
$class = new MyClass();
$class->showConstant();
-/* echo $class::constant; is not allowed */
+// echo $class::constant; is not allowed
?>
]]>
</programlisting>
http://cvs.php.net/diff.php/phpdoc/en/language/oop5/exceptions.xml?r1=1.6&r2=1.7&ty=u
Index: phpdoc/en/language/oop5/exceptions.xml
diff -u phpdoc/en/language/oop5/exceptions.xml:1.6
phpdoc/en/language/oop5/exceptions.xml:1.7
--- phpdoc/en/language/oop5/exceptions.xml:1.6 Wed Sep 29 11:54:48 2004
+++ phpdoc/en/language/oop5/exceptions.xml Sat Oct 2 05:40:50 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.6 $ -->
+<!-- $Revision: 1.7 $ -->
<sect1 id="language.oop5.exceptions">
<title>Exceptions</title>
@@ -50,7 +50,8 @@
<programlisting role="php">
<![CDATA[
<?php
-class Exception {
+class Exception
+{
protected $message = 'Unknown exception'; // exception message
protected $code = 0; // user defined exception code
protected $file; // source filename of exception
@@ -88,8 +89,8 @@
/**
* Define a custom exception class
*/
-class MyException extends Exception {
-
+class MyException extends Exception
+{
// Redefine the exception so message isn't optional
public function __construct($message, $code = 0) {
// some code
@@ -112,8 +113,8 @@
/**
* Create a class to test the exception
*/
-class TestException {
-
+class TestException
+{
public $var;
const THROW_NONE = 0;
http://cvs.php.net/diff.php/phpdoc/en/language/oop5/iterations.xml?r1=1.4&r2=1.5&ty=u
Index: phpdoc/en/language/oop5/iterations.xml
diff -u phpdoc/en/language/oop5/iterations.xml:1.4
phpdoc/en/language/oop5/iterations.xml:1.5
--- phpdoc/en/language/oop5/iterations.xml:1.4 Thu Aug 12 21:00:43 2004
+++ phpdoc/en/language/oop5/iterations.xml Sat Oct 2 05:40:50 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.4 $ -->
+<!-- $Revision: 1.5 $ -->
<sect1 id="language.oop5.iterations">
<title>Object Iteration</title>
<para>
@@ -15,26 +15,24 @@
<![CDATA[
<?php
-class MyClass {
- public $var1 = 'value 1';
- public $var2 = 'value 2';
- public $var3 = 'value 3';
-
- protected $protected = 'protected';
- private $private = 'private';
+class MyClass
+{
+ public $var1 = 'value 1';
+ public $var2 = 'value 2';
+ public $var3 = 'value 3';
+ protected $protected = 'protected';
+ private $private = 'private';
}
$class = new MyClass();
foreach($class as $key => $value) {
- print "$key => $value\n";
+ print "$key => $value\n";
}
]]>
</programlisting>
- <para>
- Will output:
- </para>
+ &example.outputs;
<screen role="php">
<![CDATA[
var1 => value 1
@@ -59,52 +57,52 @@
<programlisting role="php">
<![CDATA[
<?php
-class MyIterator implements Iterator {
+class MyIterator implements Iterator
+{
+ private $var = array();
+
+ public function __construct($array)
+ {
+ if (is_array($array)) {
+ $this->var = $array;
+ }
+ }
+
+ public function rewind() {
+ echo "rewinding\n";
+ reset($this->var);
+ }
- private $var = array();
+ public function current() {
+ $var = current($this->var);
+ echo "current: $var\n";
+ return $var;
+ }
+
+ public function key() {
+ $var = key($this->var);
+ echo "key: $var\n";
+ return $var;
+ }
- public function __construct($array) {
- if (is_array($array) ) {
- $this->var = $array;
- }
- }
-
- public function rewind() {
- echo "rewinding\n";
- reset($this->var);
- }
-
- public function current() {
- $var = current($this->var);
- echo "current: $var\n";
- return $var;
- }
-
- public function key() {
- $var = key($this->var);
- echo "key: $var\n";
- return $var;
- }
-
- public function next() {
- $var = next($this->var);
- echo "next: $var\n";
- return $var;
- }
-
- public function valid() {
- $var = $this->current() !== false;
- echo "valid: {$var}\n";
- return $var;
- }
+ public function next() {
+ $var = next($this->var);
+ echo "next: $var\n";
+ return $var;
+ }
+ public function valid() {
+ $var = $this->current() !== false;
+ echo "valid: {$var}\n";
+ return $var;
+ }
}
$values = array(1,2,3);
$it = new MyIterator($values);
foreach ($it as $a => $b) {
- print "$a: $b\n";
+ print "$a: $b\n";
}
]]>
</programlisting>
@@ -150,19 +148,19 @@
<programlisting role="php">
<![CDATA[
<?php
-class MyCollection implements IteratorAggregate {
- private $items = array();
- private $count = 0;
-
- /* Required definition of interface IteratorAggregate */
- public function getIterator() {
- return new MyIterator($this->items);
- }
-
- public function add($value) {
- $this->items[$this->count++] = $value;
- }
+class MyCollection implements IteratorAggregate
+{
+ private $items = array();
+ private $count = 0;
+
+ // Required definition of interface IteratorAggregate
+ public function getIterator() {
+ return new MyIterator($this->items);
+ }
+ public function add($value) {
+ $this->items[$this->count++] = $value;
+ }
}
$coll = new MyCollection();
@@ -171,7 +169,7 @@
$coll->add('value 3');
foreach ($coll as $key => $val) {
- echo "key/value: [$key -> $val]\n\n";
+ echo "key/value: [$key -> $val]\n\n";
}
?>
http://cvs.php.net/diff.php/phpdoc/en/language/oop5/magic.xml?r1=1.2&r2=1.3&ty=u
Index: phpdoc/en/language/oop5/magic.xml
diff -u phpdoc/en/language/oop5/magic.xml:1.2 phpdoc/en/language/oop5/magic.xml:1.3
--- phpdoc/en/language/oop5/magic.xml:1.2 Wed Sep 29 12:27:24 2004
+++ phpdoc/en/language/oop5/magic.xml Sat Oct 2 05:40:50 2004
@@ -1,9 +1,11 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.2 $ -->
+<!-- $Revision: 1.3 $ -->
<sect1 id="language.oop5.magic">
<title>Magic Methods</title>
<para>
The function names
+ <literal>__construct</literal>,
+ <literal>__destruct</literal>,
<literal>__sleep</literal>,
<literal>__wakeup</literal>, and
<literal>__toString</literal>
@@ -61,7 +63,8 @@
<![CDATA[
<?php
// Define a simple class
-class TestClass {
+class TestClass
+{
public $foo;
public function __construct($foo) {
http://cvs.php.net/diff.php/phpdoc/en/language/oop5/object-comparison.xml?r1=1.2&r2=1.3&ty=u
Index: phpdoc/en/language/oop5/object-comparison.xml
diff -u phpdoc/en/language/oop5/object-comparison.xml:1.2
phpdoc/en/language/oop5/object-comparison.xml:1.3
--- phpdoc/en/language/oop5/object-comparison.xml:1.2 Mon Aug 9 14:15:10 2004
+++ phpdoc/en/language/oop5/object-comparison.xml Sat Oct 2 05:40:51 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.2 $ -->
+<!-- $Revision: 1.3 $ -->
<sect1 id="language.oop5.object-comparison">
<title>Comparing objects</title>
<para>
@@ -25,34 +25,38 @@
<programlisting role='php'>
<![CDATA[
<?php
-function bool2str($bool) {
+function bool2str($bool)
+{
if ($bool === false) {
- return 'FALSE';
+ return 'FALSE';
} else {
- return 'TRUE';
+ return 'TRUE';
}
}
-function compareObjects(&$o1, &$o2) {
- echo 'o1 == o2 : '.bool2str($o1 == $o2)."\n";
- echo 'o1 != o2 : '.bool2str($o1 != $o2)."\n";
- echo 'o1 === o2 : '.bool2str($o1 === $o2)."\n";
- echo 'o1 !== o2 : '.bool2str($o1 !== $o2)."\n";
+function compareObjects(&$o1, &$o2)
+{
+ echo 'o1 == o2 : ' . bool2str($o1 == $o2) . "\n";
+ echo 'o1 != o2 : ' . bool2str($o1 != $o2) . "\n";
+ echo 'o1 === o2 : ' . bool2str($o1 === $o2) . "\n";
+ echo 'o1 !== o2 : ' . bool2str($o1 !== $o2) . "\n";
}
-class Flag {
- var $flag;
+class Flag
+{
+ public $flag;
- function Flag($flag=true) {
- $this->flag = $flag;
+ function Flag($flag = true) {
+ $this->flag = $flag;
}
}
-class OtherFlag {
- var $flag;
+class OtherFlag
+{
+ public $flag;
- function OtherFlag($flag=true) {
- $this->flag = $flag;
+ function OtherFlag($flag = true) {
+ $this->flag = $flag;
}
}
http://cvs.php.net/diff.php/phpdoc/en/language/oop5/overloading.xml?r1=1.5&r2=1.6&ty=u
Index: phpdoc/en/language/oop5/overloading.xml
diff -u phpdoc/en/language/oop5/overloading.xml:1.5
phpdoc/en/language/oop5/overloading.xml:1.6
--- phpdoc/en/language/oop5/overloading.xml:1.5 Wed Sep 29 11:51:49 2004
+++ phpdoc/en/language/oop5/overloading.xml Sat Oct 2 05:40:52 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.5 $ -->
+<!-- $Revision: 1.6 $ -->
<sect1 id="language.oop5.overloading">
<title>Overloading</title>
@@ -36,11 +36,13 @@
<programlisting role="php">
<![CDATA[
<?php
-class Setter {
+class Setter
+{
public $n;
private $x = array("a" => 1, "b" => 2, "c" => 3);
- function __get($nm) {
+ function __get($nm)
+ {
print "Getting [$nm]\n";
if (isset($this->x[$nm])) {
@@ -52,7 +54,8 @@
}
}
- function __set($nm, $val) {
+ function __set($nm, $val)
+ {
print "Setting [$nm] to $val\n";
if (isset($this->x[$nm])) {
@@ -131,10 +134,12 @@
<programlisting role="php">
<![CDATA[
<?php
-class Caller {
+class Caller
+{
private $x = array(1, 2, 3);
- function __call($m, $a) {
+ function __call($m, $a)
+ {
print "Method $m called:\n";
var_dump($a);
return $this->x;
http://cvs.php.net/diff.php/phpdoc/en/language/oop5/paamayim-nekudotayim.xml?r1=1.6&r2=1.7&ty=u
Index: phpdoc/en/language/oop5/paamayim-nekudotayim.xml
diff -u phpdoc/en/language/oop5/paamayim-nekudotayim.xml:1.6
phpdoc/en/language/oop5/paamayim-nekudotayim.xml:1.7
--- phpdoc/en/language/oop5/paamayim-nekudotayim.xml:1.6 Fri Aug 27 11:38:23
2004
+++ phpdoc/en/language/oop5/paamayim-nekudotayim.xml Sat Oct 2 05:40:52 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.6 $ -->
+<!-- $Revision: 1.7 $ -->
<sect1 id="language.oop5.paamayim-nekudotayim">
<title>Scope Resolution Operator (::)</title>
@@ -29,8 +29,9 @@
<![CDATA[
<?php
class MyClass {
- const CONST_VALUE = 'A constant value';
+ const CONST_VALUE = 'A constant value';
}
+
echo MyClass::CONST_VALUE;
?>
]]>
@@ -47,13 +48,14 @@
<programlisting role="php">
<![CDATA[
<?php
-class OtherClass extends MyClass {
- public static $my_static = 'static var';
-
- public static function doubleColon() {
- echo parent::CONST_VALUE . "\n";
- echo self::$my_static . "\n";
- }
+class OtherClass extends MyClass
+{
+ public static $my_static = 'static var';
+
+ public static function doubleColon() {
+ echo parent::CONST_VALUE . "\n";
+ echo self::$my_static . "\n";
+ }
}
OtherClass::doubleColon();
@@ -76,22 +78,22 @@
<programlisting role="php">
<![CDATA[
<?php
-class MyClass {
-
- protected function myFunc() {
- echo "MyClass::myFunc()\n";
- }
+class MyClass
+{
+ protected function myFunc() {
+ echo "MyClass::myFunc()\n";
+ }
}
-class OtherClass extends MyClass {
-
- /* Override parent's definition */
- public function myFunc() {
-
- /* But still call the parent function */
- parent::myFunc();
- echo "OtherClass::myFunc()\n";
- }
+class OtherClass extends MyClass
+{
+ // Override parent's definition
+ public function myFunc()
+ {
+ // But still call the parent function
+ parent::myFunc();
+ echo "OtherClass::myFunc()\n";
+ }
}
$class = new OtherClass();
http://cvs.php.net/diff.php/phpdoc/en/language/oop5/reflection.xml?r1=1.2&r2=1.3&ty=u
Index: phpdoc/en/language/oop5/reflection.xml
diff -u phpdoc/en/language/oop5/reflection.xml:1.2
phpdoc/en/language/oop5/reflection.xml:1.3
--- phpdoc/en/language/oop5/reflection.xml:1.2 Fri Aug 6 06:43:52 2004
+++ phpdoc/en/language/oop5/reflection.xml Sat Oct 2 05:40:52 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.2 $ -->
+<!-- $Revision: 1.3 $ -->
<sect1 id="language.oop5.reflection">
<title>Reflection</title>
<sect2 id="language.oop5.reflection.introduction">
@@ -18,16 +18,16 @@
<programlisting role="php">
<![CDATA[
<?php
- class Reflection { }
- interface Reflector { }
- class ReflectionException extends Exception { }
- class ReflectionFunction implements Reflector { }
- class ReflectionParameter implements Reflector { }
- class ReflectionMethod extends ReflectionFunction { }
- class ReflectionClass implements Reflector { }
- class ReflectionObject extends ReflectionClass { }
- class ReflectionProperty implements Reflector { }
- class ReflectionExtension implements Reflector { }
+class Reflection { }
+interface Reflector { }
+class ReflectionException extends Exception { }
+class ReflectionFunction implements Reflector { }
+class ReflectionParameter implements Reflector { }
+class ReflectionMethod extends ReflectionFunction { }
+class ReflectionClass implements Reflector { }
+class ReflectionObject extends ReflectionClass { }
+class ReflectionProperty implements Reflector { }
+class ReflectionExtension implements Reflector { }
?>
]]>
</programlisting>
@@ -44,12 +44,12 @@
<programlisting role='php'>
<![CDATA[
<?php
- Reflection::export(new ReflectionClass('Exception'));
+Reflection::export(new ReflectionClass('Exception'));
?>
]]>
</programlisting>
</example>
- We will see:
+ &example.outputs;
<screen>
<![CDATA[
Class [ <internal> class Exception ] {
@@ -116,22 +116,23 @@
<programlisting role="php">
<![CDATA[
<?php
- class ReflectionFunction implements Reflector {
- public object __construct(string name)
- public string __toString()
- public static string export()
- public string getName()
- public bool isInternal()
- public bool isUserDefined()
- public string getFileName()
- public int getStartLine()
- public int getEndLine()
- public string getDocComment()
- public array getStaticVariables()
- public mixed invoke(mixed* args)
- public bool returnsReference()
- public ReflectionParameter[] getParameters()
- }
+class ReflectionFunction implements Reflector
+{
+ public object __construct(string name)
+ public string __toString()
+ public static string export()
+ public string getName()
+ public bool isInternal()
+ public bool isUserDefined()
+ public string getFileName()
+ public int getStartLine()
+ public int getEndLine()
+ public string getDocComment()
+ public array getStaticVariables()
+ public mixed invoke(mixed* args)
+ public bool returnsReference()
+ public ReflectionParameter[] getParameters()
+}
?>
]]>
</programlisting>
@@ -154,7 +155,6 @@
function counter()
{
static $c = 0;
-
return $c++;
}
@@ -213,16 +213,17 @@
<programlisting role="php">
<![CDATA[
<?php
- class ReflectionParameter implements Reflector {
- public object __construct(string name)
- public string __toString()
- public static string export()
- public string getName()
- public ReflectionClass getClass()
- public bool allowsNull()
- public bool isPassedByReference()
- public bool isOptional()
- }
+class ReflectionParameter implements Reflector
+{
+ public object __construct(string name)
+ public string __toString()
+ public static string export()
+ public string getName()
+ public ReflectionClass getClass()
+ public bool allowsNull()
+ public bool isPassedByReference()
+ public bool isOptional()
+}
?>
]]>
</programlisting>
@@ -243,34 +244,33 @@
<programlisting role='php'>
<![CDATA[
<?php
- function foo($a, $b, $c) { }
- function bar(Exception $a, &$b, $c) { }
- function baz(ReflectionFunction $a, $b = 1, $c = null) { }
- function abc() { }
-
- // Create an instance of Reflection_Function with the
- // parameter given from the command line.
- $reflect = new ReflectionFunction($argv[1]);
-
- echo $reflect;
-
- foreach ($reflect->getParameters() as $i => $param)
- {
- printf(
- "-- Parameter #%d: %s {\n".
- " Class: %s\n".
- " Allows NULL: %s\n".
- " Passed to by reference: %s\n".
- " Is optional?: %s\n".
- "}\n",
- $i,
- $param->getName(),
- var_export($param->getClass(), 1),
- var_export($param->allowsNull(), 1),
- var_export($param->isPassedByReference(), 1),
- $param->isOptional() ? 'yes' : 'no'
- );
- }
+function foo($a, $b, $c) { }
+function bar(Exception $a, &$b, $c) { }
+function baz(ReflectionFunction $a, $b = 1, $c = null) { }
+function abc() { }
+
+// Create an instance of Reflection_Function with the
+// parameter given from the command line.
+$reflect = new ReflectionFunction($argv[1]);
+
+echo $reflect;
+
+foreach ($reflect->getParameters() as $i => $param) {
+ printf(
+ "-- Parameter #%d: %s {\n".
+ " Class: %s\n".
+ " Allows NULL: %s\n".
+ " Passed to by reference: %s\n".
+ " Is optional?: %s\n".
+ "}\n",
+ $i,
+ $param->getName(),
+ var_export($param->getClass(), 1),
+ var_export($param->allowsNull(), 1),
+ var_export($param->isPassedByReference(), 1),
+ $param->isOptional() ? 'yes' : 'no'
+ );
+}
?>
]]>
</programlisting>
@@ -287,35 +287,36 @@
<programlisting role="php">
<![CDATA[
<?php
- class ReflectionClass implements Reflector {
- public __construct(string name)
- public string __toString()
- public static string export()
- public string getName()
- public bool isInternal()
- public bool isUserDefined()
- public string getFileName()
- public int getStartLine()
- public int getEndLine()
- public string getDocComment()
- public ReflectionMethod getConstructor()
- public ReflectionMethod getMethod(string name)
- public ReflectionMethod[] getMethods()
- public ReflectionProperty getProperty(string name)
- public ReflectionProperty[] getProperties()
- public array getConstants()
- public mixed getConstant(string name)
- public bool isInstantiable()
- public bool isInterface()
- public bool isFinal()
- public bool isAbstract()
- public int getModifiers()
- public bool isInstance(stdclass object)
- public stdclass newInstance(mixed* args)
- public ReflectionClass[] getInterfaces()
- public ReflectionClass getParentClass()
- public bool isSubclassOf(ReflectionClass class)
- }
+class ReflectionClass implements Reflector
+{
+ public __construct(string name)
+ public string __toString()
+ public static string export()
+ public string getName()
+ public bool isInternal()
+ public bool isUserDefined()
+ public string getFileName()
+ public int getStartLine()
+ public int getEndLine()
+ public string getDocComment()
+ public ReflectionMethod getConstructor()
+ public ReflectionMethod getMethod(string name)
+ public ReflectionMethod[] getMethods()
+ public ReflectionProperty getProperty(string name)
+ public ReflectionProperty[] getProperties()
+ public array getConstants()
+ public mixed getConstant(string name)
+ public bool isInstantiable()
+ public bool isInterface()
+ public bool isFinal()
+ public bool isAbstract()
+ public int getModifiers()
+ public bool isInstance(stdclass object)
+ public stdclass newInstance(mixed* args)
+ public ReflectionClass[] getInterfaces()
+ public ReflectionClass getParentClass()
+ public bool isSubclassOf(ReflectionClass class)
+}
?>
]]>
</programlisting>
@@ -330,85 +331,82 @@
<programlisting role='php'>
<![CDATA[
<?php
- interface Serializable
- {
- // ...
- }
+interface Serializable
+{
+ // ...
+}
- class Object
- {
- // ...
- }
+class Object
+{
+ // ...
+}
- /**
- * A counter class
- *
- */
- class Counter extends Object implements Serializable
- {
- const START = 0;
- private static $c = Counter::START;
-
- /**
- * Invoke counter
- *
- * @access public
- * @return int
- */
- public function count()
- {
- return self::$c++;
- }
- }
+/**
+ * A counter class
+ */
+class Counter extends Object implements Serializable
+{
+ const START = 0;
+ private static $c = Counter::START;
+
+ /**
+ * Invoke counter
+ *
+ * @access public
+ * @return int
+ */
+ public function count() {
+ return self::$c++;
+ }
+}
+
+// Create an instance of the ReflectionClass class
+$class= new ReflectionClass('Counter');
+
+// Print out basic information
+printf(
+ "===> The %s%s%s %s '%s' [extends %s]\n" .
+ " declared in %s\n" .
+ " lines %d to %d\n" .
+ " having the modifiers %d [%s]\n",
+ $class->isInternal() ? 'internal' : 'user-defined',
+ $class->isAbstract() ? ' abstract' : '',
+ $class->isFinal() ? ' final' : '',
+ $class->isInterface() ? 'interface' : 'class',
+ $class->getName(),
+ var_export($class->getParentClass(), 1),
+ $class->getFileName(),
+ $class->getStartLine(),
+ $class->getEndline(),
+ $class->getModifiers(),
+ implode(' ', Reflection::getModifierNames($class->getModifiers()))
+);
- // Create an instance of the ReflectionClass class
- $class= new ReflectionClass('Counter');
+// Print documentation comment
+printf("---> Documentation:\n %s\n", var_export($class->getDocComment(), 1));
- // Print out basic information
- printf(
- "===> The %s%s%s %s '%s' [extends %s]\n".
- " declared in %s\n".
- " lines %d to %d\n".
- " having the modifiers %d [%s]\n",
- $class->isInternal() ? 'internal' : 'user-defined',
- $class->isAbstract() ? ' abstract' : '',
- $class->isFinal() ? ' final' : '',
- $class->isInterface() ? 'interface' : 'class',
- $class->getName(),
- var_export($class->getParentClass(), 1),
- $class->getFileName(),
- $class->getStartLine(),
- $class->getEndline(),
- $class->getModifiers(),
- implode(' ', Reflection::getModifierNames($class->getModifiers()))
- );
-
- // Print documentation comment
- printf("---> Documentation:\n %s\n", var_export($class->getDocComment(), 1));
-
- // Print which interfaces are implemented by this class
- printf("---> Implements:\n %s\n", var_export($class->getInterfaces(), 1));
-
- // Print class constants
- printf("---> Constants: %s\n", var_export($class->getConstants(), 1));
-
- // Print class properties
- printf("---> Properties: %s\n", var_export($class->getProperties(), 1));
-
- // Print class methods
- printf("---> Methods: %s\n", var_export($class->getMethods(), 1));
-
- // If this class is instantiable, create an instance
- if ($class->isInstantiable())
- {
- $counter= $class->newInstance();
+// Print which interfaces are implemented by this class
+printf("---> Implements:\n %s\n", var_export($class->getInterfaces(), 1));
- echo '---> $counter is instance? ';
- echo $class->isInstance($counter) ? 'yes' : 'no';
+// Print class constants
+printf("---> Constants: %s\n", var_export($class->getConstants(), 1));
- echo "\n---> new Object() is instance? ";
- echo $class->isInstance(new Object()) ? 'yes' : 'no';
- }
+// Print class properties
+printf("---> Properties: %s\n", var_export($class->getProperties(), 1));
+
+// Print class methods
+printf("---> Methods: %s\n", var_export($class->getMethods(), 1));
+
+// If this class is instantiable, create an instance
+if ($class->isInstantiable()) {
+ $counter= $class->newInstance();
+
+ echo '---> $counter is instance? ';
+ echo $class->isInstance($counter) ? 'yes' : 'no';
+
+ echo "\n---> new Object() is instance? ";
+ echo $class->isInstance(new Object()) ? 'yes' : 'no';
+}
?>
]]>
</programlisting>
@@ -439,33 +437,34 @@
<programlisting role="php">
<![CDATA[
<?php
- class ReflectionMethod extends ReflectionFunction {
- public __construct(mixed class, string name)
- public static string export()
- public mixed invoke(stdclass object, mixed* args)
- public bool isFinal()
- public bool isAbstract()
- public bool isPublic()
- public bool isPrivate()
- public bool isProtected()
- public bool isStatic()
- public bool isConstructor()
- public int getModifiers()
- public ReflectionClass getDeclaringClass()
-
- /* Inherited from ReflectionFunction */
- public string __toString()
- public string getName()
- public bool isInternal()
- public bool isUserDefined()
- public string getFileName()
- public int getStartLine()
- public int getEndLine()
- public string getDocComment()
- public array getStaticVariables()
- public bool returnsReference()
- public ReflectionParameter[] getParameters()
- }
+class ReflectionMethod extends ReflectionFunction
+{
+ public __construct(mixed class, string name)
+ public static string export()
+ public mixed invoke(stdclass object, mixed* args)
+ public bool isFinal()
+ public bool isAbstract()
+ public bool isPublic()
+ public bool isPrivate()
+ public bool isProtected()
+ public bool isStatic()
+ public bool isConstructor()
+ public int getModifiers()
+ public ReflectionClass getDeclaringClass()
+
+ // Inherited from ReflectionFunction
+ public string __toString()
+ public string getName()
+ public bool isInternal()
+ public bool isUserDefined()
+ public string getFileName()
+ public int getStartLine()
+ public int getEndLine()
+ public string getDocComment()
+ public array getStaticVariables()
+ public bool returnsReference()
+ public ReflectionParameter[] getParameters()
+}
?>
]]>
</programlisting>
@@ -480,61 +479,60 @@
<programlisting role='php'>
<![CDATA[
<?php
- class Counter {
- private static $c = 0;
+class Counter
+{
+ private static $c = 0;
- /**
- * Increment counter
- *
- * @final
- * @static
- * @access public
- * @return int
- */
- final public static function increment()
- {
- self::$c++;
- return self::$c;
- }
- }
+ /**
+ * Increment counter
+ *
+ * @final
+ * @static
+ * @access public
+ * @return int
+ */
+ final public static function increment()
+ {
+ return ++self::$c;
+ }
+}
- // Create an instance of the Reflection_Method class
- $method= new ReflectionMethod('Counter', 'increment');
+// Create an instance of the Reflection_Method class
+$method= new ReflectionMethod('Counter', 'increment');
- // Print out basic information
- printf(
- "===> The %s%s%s%s%s%s%s method '%s' (which is %s)\n".
- " declared in %s\n".
- " lines %d to %d\n".
+// Print out basic information
+printf(
+ "===> The %s%s%s%s%s%s%s method '%s' (which is %s)\n" .
+ " declared in %s\n" .
+ " lines %d to %d\n" .
" having the modifiers %d[%s]\n",
- $method->isInternal() ? 'internal' : 'user-defined',
- $method->isAbstract() ? ' abstract' : '',
- $method->isFinal() ? ' final' : '',
- $method->isPublic() ? ' public' : '',
- $method->isPrivate() ? ' private' : '',
- $method->isProtected() ? ' protected' : '',
- $method->isStatic() ? ' static' : '',
- $method->getName(),
- $method->isConstructor() ? 'the constructor' : 'a regular method',
- $method->getFileName(),
- $method->getStartLine(),
- $method->getEndline(),
- $method->getModifiers(),
- implode(' ', Reflection::getModifierNames($method->getModifiers()))
- );
-
- // Print documentation comment
- printf("---> Documentation:\n %s\n", var_export($method->getDocComment(), 1));
-
- // Print static variables if existant
- if ($statics= $method->getStaticVariables())
- {
- printf("---> Static variables: %s\n", var_export($statics, 1));
- }
+ $method->isInternal() ? 'internal' : 'user-defined',
+ $method->isAbstract() ? ' abstract' : '',
+ $method->isFinal() ? ' final' : '',
+ $method->isPublic() ? ' public' : '',
+ $method->isPrivate() ? ' private' : '',
+ $method->isProtected() ? ' protected' : '',
+ $method->isStatic() ? ' static' : '',
+ $method->getName(),
+ $method->isConstructor() ? 'the constructor' : 'a regular method',
+ $method->getFileName(),
+ $method->getStartLine(),
+ $method->getEndline(),
+ $method->getModifiers(),
+ implode(' ', Reflection::getModifierNames($method->getModifiers()))
+);
+
+// Print documentation comment
+printf("---> Documentation:\n %s\n", var_export($method->getDocComment(), 1));
+
+// Print static variables if existant
+if ($statics= $method->getStaticVariables()) {
+ printf("---> Static variables: %s\n", var_export($statics, 1));
+}
- // Invoke the method
- printf("---> Invokation results in: ");
- var_dump($method->invoke(NULL));
+// Invoke the method
+printf("---> Invokation results in: ");
+var_dump($method->invoke(NULL));
?>
]]>
</programlisting>
@@ -565,21 +563,22 @@
<programlisting role="php">
<![CDATA[
<?php
- class ReflectionProperty implements Reflector {
- public __construct(mixed class, string name)
- public string __toString()
- public static string export()
- public string getName()
- public bool isPublic()
- public bool isPrivate()
- public bool isProtected()
- public bool isStatic()
- public bool isDefault()
- public int getModifiers()
- public mixed getValue(stdclass object)
- public void setValue(stdclass object, mixed value)
- public ReflectionClass getDeclaringClass()
- }
+class ReflectionProperty implements Reflector
+{
+ public __construct(mixed class, string name)
+ public string __toString()
+ public static string export()
+ public string getName()
+ public bool isPublic()
+ public bool isPrivate()
+ public bool isProtected()
+ public bool isStatic()
+ public bool isDefault()
+ public int getModifiers()
+ public mixed getValue(stdclass object)
+ public void setValue(stdclass object, mixed value)
+ public ReflectionClass getDeclaringClass()
+}
?>
]]>
</programlisting>
@@ -594,41 +593,41 @@
<programlisting role='php'>
<![CDATA[
<?php
- class String
- {
- public $length = 5;
- }
+class String
+{
+ public $length = 5;
+}
+
+// Create an instance of the ReflectionProperty class
+$prop = new ReflectionProperty('String', 'length');
+
+// Print out basic information
+printf(
+ "===> The%s%s%s%s property '%s' (which was %s)\n" .
+ " having the modifiers %s\n",
+ $prop->isPublic() ? ' public' : '',
+ $prop->isPrivate() ? ' private' : '',
+ $prop->isProtected() ? ' protected' : '',
+ $prop->isStatic() ? ' static' : '',
+ $prop->getName(),
+ $prop->isDefault() ? 'declared at compile-time' : 'created at run-time',
+ var_export(Reflection::getModifierNames($prop->getModifiers()), 1)
+);
- // Create an instance of the ReflectionProperty class
- $prop = new ReflectionProperty('String', 'length');
+// Create an instance of String
+$obj= new String();
- // Print out basic information
- printf(
- "===> The%s%s%s%s property '%s' (which was %s)\n".
- " having the modifiers %s\n",
- $prop->isPublic() ? ' public' : '',
- $prop->isPrivate() ? ' private' : '',
- $prop->isProtected() ? ' protected' : '',
- $prop->isStatic() ? ' static' : '',
- $prop->getName(),
- $prop->isDefault() ? 'declared at compile-time' : 'created at run-time',
- var_export(Reflection::getModifierNames($prop->getModifiers()), 1)
- );
-
- // Create an instance of String
- $obj= new String();
-
- // Get current value
- printf("---> Value is: ");
- var_dump($prop->getValue($obj));
-
- // Change value
- $prop->setValue($obj, 10);
- printf("---> Setting value to 10, new value is: ");
- var_dump($prop->getValue($obj));
+// Get current value
+printf("---> Value is: ");
+var_dump($prop->getValue($obj));
+
+// Change value
+$prop->setValue($obj, 10);
+printf("---> Setting value to 10, new value is: ");
+var_dump($prop->getValue($obj));
- // Dump object
- var_dump($obj);
+// Dump object
+var_dump($obj);
?>
]]>
</programlisting>
@@ -652,16 +651,16 @@
<programlisting role="php">
<![CDATA[
<?php
- class ReflectionExtension implements Reflector {
- public __construct(string name)
- public string __toString()
- public static string export()
- public string getName()
- public string getVersion()
- public ReflectionFunction[] getFunctions()
- public array getConstants()
- public array getINIEntries()
- }
+class ReflectionExtension implements Reflector {
+ public __construct(string name)
+ public string __toString()
+ public static string export()
+ public string getName()
+ public string getVersion()
+ public ReflectionFunction[] getFunctions()
+ public array getConstants()
+ public array getINIEntries()
+}
?>
]]>
</programlisting>
@@ -676,25 +675,25 @@
<programlisting role='php'>
<![CDATA[
<?php
- // Create an instance of the ReflectionProperty class
- $ext = new ReflectionExtension('standard');
+// Create an instance of the ReflectionProperty class
+$ext = new ReflectionExtension('standard');
- // Print out basic information
- printf(
- "Name : %s\n".
- "Version : %s\n".
- "Functions : [%d] %s\n".
- "Constants : [%d] %s\n".
- "INI entries : [%d] %s\n",
- $ext->getName(),
- $ext->getVersion() ? $ext->getVersion() : 'NO_VERSION',
- sizeof($ext->getFunctions()),
- var_export($ext->getFunctions(), 1),
- sizeof($ext->getConstants()),
- var_export($ext->getConstants(), 1),
- sizeof($ext->getINIEntries()),
- var_export($ext->getINIEntries(), 1)
- );
+// Print out basic information
+printf(
+ "Name : %s\n" .
+ "Version : %s\n" .
+ "Functions : [%d] %s\n" .
+ "Constants : [%d] %s\n" .
+ "INI entries : [%d] %s\n",
+ $ext->getName(),
+ $ext->getVersion() ? $ext->getVersion() : 'NO_VERSION',
+ sizeof($ext->getFunctions()),
+ var_export($ext->getFunctions(), 1),
+ sizeof($ext->getConstants()),
+ var_export($ext->getConstants(), 1),
+ sizeof($ext->getINIEntries()),
+ var_export($ext->getINIEntries(), 1)
+);
?>
]]>
</programlisting>
@@ -714,37 +713,38 @@
<programlisting role='php'>
<![CDATA[
<?php
- /**
- * My Reflection_Method class
- *
- */
- class My_Reflection_Method extends ReflectionMethod {
- public $visibility= '';
-
- public function __construct($o, $m) {
- parent::__construct($o, $m);
- $this->visibility= Reflection::getModifierNames($this->getModifiers());
+/**
+ * My Reflection_Method class
+ */
+class My_Reflection_Method extends ReflectionMethod
+{
+ public $visibility = '';
+
+ public function __construct($o, $m)
+ {
+ parent::__construct($o, $m);
+ $this->visibility= Reflection::getModifierNames($this->getModifiers());
}
- }
+}
- /**
- * Demo class #1
- *
- */
- class T {
+/**
+ * Demo class #1
+ *
+ */
+class T {
protected function x() {}
- }
+}
- /**
- * Demo class #2
- *
- */
- class U extends T {
+/**
+ * Demo class #2
+ *
+ */
+class U extends T {
function x() {}
- }
+}
- // Print out information
- var_dump(new My_Reflection_Method('U', 'x'));
+// Print out information
+var_dump(new My_Reflection_Method('U', 'x'));
?>
]]>
</programlisting>
http://cvs.php.net/diff.php/phpdoc/en/language/oop5/static.xml?r1=1.4&r2=1.5&ty=u
Index: phpdoc/en/language/oop5/static.xml
diff -u phpdoc/en/language/oop5/static.xml:1.4 phpdoc/en/language/oop5/static.xml:1.5
--- phpdoc/en/language/oop5/static.xml:1.4 Thu Sep 30 14:22:30 2004
+++ phpdoc/en/language/oop5/static.xml Sat Oct 2 05:40:52 2004
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.4 $ -->
+<!-- $Revision: 1.5 $ -->
<sect1 id="language.oop5.static">
<title>Static Keyword</title>
@@ -43,19 +43,20 @@
<programlisting role="php">
<![CDATA[
<?php
-class Foo {
- public static $my_static = 'foo';
-
- public function staticValue() {
- return self::$my_static;
- }
+class Foo
+{
+ public static $my_static = 'foo';
+
+ public function staticValue() {
+ return self::$my_static;
+ }
}
-class Bar extends Foo {
-
- public function fooStatic() {
- return parent::$my_static;
- }
+class Bar extends Foo
+{
+ public function fooStatic() {
+ return parent::$my_static;
+ }
}
@@ -65,7 +66,7 @@
print $foo->staticValue() . "\n";
print $foo->my_static . "\n"; // Undefined "Property" my_static
-// $foo::my_static is not possible
+// $foo::my_static is not possible
print Bar::$my_static . "\n";
$bar = new Bar();
@@ -81,9 +82,9 @@
<![CDATA[
<?php
class Foo {
- public static function aStaticMethod() {
- // ...
- }
+ public static function aStaticMethod() {
+ // ...
+ }
}
Foo::aStaticMethod();