Update Reflection API class names. Whitespace fixes.

This commit is contained in:
Sebastian Bergmann 2004-05-26 07:00:39 +00:00
parent 17df3ec21b
commit 2fbfcd7482

View File

@ -21,9 +21,9 @@ Changes in the Zend Engine 2.0
* $this
Unlike in Zend Engine 1 the pseudo variable $this cannot be
exchanged in Zend Engine 2. You can of course modify or work with
an object by using $this but you cannot replace $this with another
Unlike in Zend Engine 1 the pseudo variable $this cannot be
exchanged in Zend Engine 2. You can of course modify or work with
an object by using $this but you cannot replace $this with another
object to change the original object.
Example:
@ -35,17 +35,17 @@ Changes in the Zend Engine 2.0
$this = $other;
}
}
$object = new Foo;
$object->prop = 'Hello';
$other = new Foo;
$other->prop = 'Bye';
$object->replace($other);
print $object->prop; // still shows 'Hello'
?>
Zend Engine 2.0 will issue a compile error, if an assignment
@ -53,9 +53,9 @@ Changes in the Zend Engine 2.0
* Private and Protected Members.
The Zend Engine 2.0 introduces private and protected member
variables. Note that for performance reasons no error message is
emitted in case of an illegal access to a private or protectecd
The Zend Engine 2.0 introduces private and protected member
variables. Note that for performance reasons no error message is
emitted in case of an illegal access to a private or protectecd
member variable.
Example:
@ -75,7 +75,7 @@ Changes in the Zend Engine 2.0
class MyClass2 extends MyClass {
protected $Foo;
function printHello() {
MyClass::printHello(); /* Should print */
print "MyClass2::printHello() " . $this->Hello; /* Shouldn't print out anything */
@ -96,9 +96,9 @@ Changes in the Zend Engine 2.0
print $obj->Foo; /* Shouldn't print out anything */
$obj->printHello();
?>
Protected member variables can be accessed in classes extending the
class they are declared in, whereas private member variables can
Protected member variables can be accessed in classes extending the
class they are declared in, whereas private member variables can
only be accessed by the class they belong to.
* Private and protected methods.
@ -130,14 +130,14 @@ Changes in the Zend Engine 2.0
$o->aPublicMethod();
?>
Old code that has no user-defined classes or functions named
Old code that has no user-defined classes or functions named
'public', 'protected' or 'private' should run without modifications.
* Abstract Classes and Methods.
The Zend Engine 2.0 introduces abstract classes and methods. An
abstract method only declares the method's signature and does not
provide an implementation. A class that contains abstract methods
The Zend Engine 2.0 introduces abstract classes and methods. An
abstract method only declares the method's signature and does not
provide an implementation. A class that contains abstract methods
needs to be declared abstract.
Example:
@ -160,7 +160,7 @@ Changes in the Zend Engine 2.0
Classes that do not have abstract methods can be declared abstract
to prevent them from being instantiated.
Old code that has no user-defined classes or functions named
Old code that has no user-defined classes or functions named
'abstract' should run without modifications.
* Interfaces.
@ -182,13 +182,13 @@ Changes in the Zend Engine 2.0
}
?>
Old code that has no user-defined classes or functions named
Old code that has no user-defined classes or functions named
'interface' or 'implements' should run without modifications.
An interface may extend one or more base interfaces (but not
An interface may extend one or more base interfaces (but not
implement them). Neither a class nor an interface can inherit
methods of the same name from different root interfaces.
methods of the same name from different root interfaces.
Interfaces may contain abstract static methods.
Example:
@ -197,7 +197,7 @@ Changes in the Zend Engine 2.0
interface Printable {
function dump();
}
interface Streamable extends Printable {
function writeToStream();
static function readFromStream();
@ -215,14 +215,14 @@ Changes in the Zend Engine 2.0
}
}
?>
A class that does not implement all interface methods must be
A class that does not implement all interface methods must be
declared as an abstract class.
* Class Type Hints.
While remaining loosely typed the Zend Engine 2.0 introduces the
ability to use class type hints to declare the expected class of
While remaining loosely typed the Zend Engine 2.0 introduces the
ability to use class type hints to declare the expected class of
objects that are passed as parameters to a method.
Example:
@ -275,7 +275,7 @@ Changes in the Zend Engine 2.0
* Final methods and classes.
The Zend Engine 2.0 introduces the "final" keyword to declare
final methods. Those cannot be overridden by sub-classes.
final methods. Those cannot be overridden by sub-classes.
Example:
@ -287,8 +287,8 @@ Changes in the Zend Engine 2.0
}
?>
It is furthermore possible to make a class final. Doing this
prevents a class from being specialized (it cannot be inherited
It is furthermore possible to make a class final. Doing this
prevents a class from being specialized (it cannot be inherited
by another class). There's no need to declare the methods of
a final class themselves as final.
@ -304,7 +304,7 @@ Changes in the Zend Engine 2.0
Properties cannot be final. See per-class constants below.
Old code that has no user-defined classes or functions named
Old code that has no user-defined classes or functions named
'final' should run without modifications.
* Object Cloning.
@ -339,9 +339,9 @@ Changes in the Zend Engine 2.0
all of the object's properties. If a __clone() method is
defined, then it will be responsible to set the necessary
properties in the created object. For convenience, the engine
ensures, that the clone will be initialized with all of the
properties from the source object, so that developers can start
with a by-value replica of the source object, and only override
ensures, that the clone will be initialized with all of the
properties from the source object, so that developers can start
with a by-value replica of the source object, and only override
properties that need to be changed.
Example:
@ -374,7 +374,7 @@ Changes in the Zend Engine 2.0
print $obj_clone->name . "\n";
print $obj_clone->address . "\n";
?>
* Unified Constructors.
The Zend Engine allows developers to declare constructor methods
@ -474,7 +474,7 @@ Changes in the Zend Engine 2.0
echo 'Foo::constant = ' . Foo::constant . "\n";
?>
Old code that has no user-defined classes or functions
Old code that has no user-defined classes or functions
named 'const' will run without modifications.
* Exceptions.
@ -483,16 +483,16 @@ Changes in the Zend Engine 2.0
introduces a exception model similar to that of other programming
languages. But there is no catch all and no finally clause.
Old code that has no user-defined classes or functions 'catch',
Old code that has no user-defined classes or functions 'catch',
'throw' and 'try' will run without modifications.
Exceptions can be rethrown in catch blocks. Also it is possible to
have multiple catch blocks. In that case the caught exception is
have multiple catch blocks. In that case the caught exception is
compared with the classtype of each catch block from top to bottom
and the first block that has a 'instanceof' match gets executed.
When the catch block finishes execution continues at the end of
When the catch block finishes execution continues at the end of
the last catch block. If no catch block has a 'instanceof' match
then the next try/catch block is searched until no more try/catch
then the next try/catch block is searched until no more try/catch
blocks are available. In that case the exception is an uncaught
exception and the program terminates with showing the exception.
@ -529,18 +529,18 @@ Changes in the Zend Engine 2.0
echo $exception;
}
?>
Even though the above example shows that it is possible to define
exception classes that don't inherit from Exception it is best to
do so. This is because the internal Exception class can gather a
lot of information otherwise not available. The PHP code emulation
code would look something like shown below. The comments show the
meaning of each property. As the code shows it is possible to read
meaning of each property. As the code shows it is possible to read
any available information by using the getter methods. But since
some of the methods are used internally they are marked final. All
in all the class is very restrictive because it must be ensured
some of the methods are used internally they are marked final. All
in all the class is very restrictive because it must be ensured
that anything used internally always works as expected.
Emulating class Exception:
<?php
@ -555,15 +555,15 @@ Changes in the Zend Engine 2.0
$this->trace = debug_backtrace();
$this->string = StringFormat($this);
}
protected $message = 'Unknown exception'; // exception message
protected $message = 'Unknown exception'; // exception message
protected $code = 0; // user defined exception code
protected $file; // source filename of exception
protected $line; // source line of exception
private $trace; // backtrace of exception
private $string; // internal only!!
final function getMessage() {
return $this->message;
}
@ -592,19 +592,19 @@ Changes in the Zend Engine 2.0
}
}
?>
If you derive your exception classes from this Exception base class
your exceptions will be nicely shown in the builtin handler for
your exceptions will be nicely shown in the builtin handler for
uncaught exceptions.
Note: The method getMessage() is a final read only access method to
Note: The method getMessage() is a final read only access method to
the private proeprty message that is set in the constructor. If you
feel a need to overwrite the exception display then overload method
__toString() in your derived class or implement your own extneral
__toString() in your derived class or implement your own extneral
exception display function to accomplish your desired formatting.
Example:
<?php
function display_exception(Exception $ex)
{
@ -612,7 +612,7 @@ Changes in the Zend Engine 2.0
echo $ex->getTrace();
echo '</pre>';
}
try
{
// your code here
@ -662,9 +662,9 @@ Changes in the Zend Engine 2.0
}
print foo::$my_static;
$obj = foo;
print $obj->my_prop;
?>
@ -691,14 +691,14 @@ Changes in the Zend Engine 2.0
* instanceof.
New support for an instanceof operator which checks if an object
is of a certain class or interface type.
Example:
<?php
class Foo {
}
$obj = new Foo();
if ($obj instanceof Foo) {
print "Yay!\n";
@ -720,9 +720,9 @@ Changes in the Zend Engine 2.0
* __autoload().
The __autoload() interceptor function will be automatically called
when an undeclared class is to be instantiated. The name of that
class will be passed to the __autoload() interceptor function as its
The __autoload() interceptor function will be automatically called
when an undeclared class is to be instantiated. The name of that
class will be passed to the __autoload() interceptor function as its
only argument. __autoload() must succeed in loading the class. If it
doesn't then an E_ERROR is emitted.
@ -817,24 +817,24 @@ Changes in the Zend Engine 2.0
}
?>
Each class whose instances can be iterated with foreach should
Each class whose instances can be iterated with foreach should
implement the empty interface 'Traversable'. Hence any object
that says it implements 'Traversable' can be used with foreach.
The interfaces 'IteratorAggregate' and 'Iterator' allow to specify
how class objects are iterated in PHP code. The first of them simply
has a method 'getIterator' which must return an object that either
implements the interface 'Iterator' or is instantiated from an
has a method 'getIterator' which must return an object that either
implements the interface 'Iterator' or is instantiated from an
internal class that can be iterated.
Example:
<?php
class ObjectIterator implements Iterator {
private $obj;
private $num;
function __construct($obj) {
$this->obj = $obj;
}
@ -859,23 +859,23 @@ Changes in the Zend Engine 2.0
$this->num++;
}
}
class Object implements IteratorAggregate {
public $max = 3;
function getIterator() {
return new ObjectIterator($this);
}
}
}
$obj = new Object;
// this foreach ...
foreach($obj as $key => $val) {
echo "$key = $val\n";
}
// matches the following 7 lines with the for directive.
$it = $obj->getIterator();
for($it->rewind(); $it->valid(); $it->next()) {
@ -886,14 +886,14 @@ Changes in the Zend Engine 2.0
unset($it);
?>
The matching for directive is very intersting here since it shows
The matching for directive is very intersting here since it shows
the use of all abstract methods declared in the interfaces Iterator
and IteratorAggregate respectively.
* __METHOD__
The pseudo constant __METHOD__ shows the current class and method
when used inside a method and the function when used outside of a
The pseudo constant __METHOD__ shows the current class and method
when used inside a method and the function when used outside of a
class.
Example:
@ -911,9 +911,9 @@ Changes in the Zend Engine 2.0
* __toString()
The magic method __toString() allows to overload the object to
string conversion. This conversion is only done automatically for
the printing functions (echo, print) but not for other functions
The magic method __toString() allows to overload the object to
string conversion. This conversion is only done automatically for
the printing functions (echo, print) but not for other functions
that expect strings. Also the function __toString is not used in
places where objects are not allowed but strings are like array
indices. Note that specialized objects may be converted to a string
@ -940,16 +940,16 @@ Changes in the Zend Engine 2.0
?>
* Reflection API
PHP5 comes with a complete reflection API that adds the ability to
PHP 5 comes with a complete Reflection API that adds the ability to
reverse-engineer classes, interfaces, functions and methods as well
as extensions.
The reflection API also offers ways of getting doc comments for
The Reflection API also offers ways of getting doc comments for
functions, classes and methods.
Nearly all aspects of object oriented code can be reflected by
using the reflection API which is documented separatley:
using the Reflection API which is documented separately:
http://sitten-polizei.de/php/reflection_api/docs/language.reflection.html
Example:
@ -962,11 +962,11 @@ Changes in the Zend Engine 2.0
}
}
reflection_class::export('Foo');
reflection_object::export(new Foo);
reflection_method::export('Foo', 'func');
reflection_property::export('Foo', 'prop');
reflection_extension::export('standard');
ReflectionClass::export('Foo');
ReflectionObject::export(new Foo);
ReflectionMethod::export('Foo', 'func');
ReflectionProperty::export('Foo', 'prop');
ReflectionExtension::export('standard');
?>
* New memory manager
@ -977,7 +977,7 @@ Changes in the Zend Engine 2.0
* Others
Probably other changes which we forgot to list. This list will be kept up-to-date
as much as possible.
Changes in the Zend Engine 1.0