Lecture
Это окончание невероятной информации про объектно-ориентированное программирование.
...
method
When an object variable is converted to a string, the result is the string "Object id #n", where n is the number of the object in the global object table. If necessary (albeit extremely rarely), this mechanism can be changed by creating a __toString () method for the class that returns some string representation of the current object.
Although PHP5 beta 3 does not fully work with this algorithm (__toString () only works when using a pointer to an object in the print statement), this opens up interesting perspectives. For example, the following code is a variation on PHP typing:
class Integer {
private $ value;
function __construct ($ val) {
$ this-> value = $ val;
}
function __toString () {
return (string) ($ this-> value);
}
}
$ i = new Integer (10);
/ **
Theoretically, $ i when converting to a string should give "10",
and since the number 10 is compared with a string, it must
be cast to string. It turns out "10" == "10". In practice, in
In this case, the conversion of $ i to a string is performed by
PHP4 (i.e., the result is the string "Object").
* /
if (10 == $ i)
echo '10 !!!! :-) ';
Reflection API
Reflection is not a new concept for PHP, but only in PHP5 an attempt has been made to bring the work with the structural objects of the language to a general form. Structural objects are functions, classes, interfaces, parameters, and extensions.
Reflection classes allow you to get information about objects of the language directly during the execution of the script. For example, you can get information about an object, including its methods, their parameters, which file contains the description of the object and even which document comment is in front of it.
Reflection classes are made for each structural language object:
Unlike most other changes in PHP5, Reflections are already well documented. A detailed description is available at http://sitten-polizei.de/php/reflection_api/docs/language.reflection.html.
An example of using Reflection:
/ **
MyClass is just an example class for demonstrating Reflection.
This code will be displayed as documentation for the class MyClass with Reflection.
* /
class MyClass {
/ **
And this is a comment to the constructor.
* /
function __construct () {
}
}
Reflection :: export (new Reflection_Class ('MyClass'));
The result of this code will be the following class description:
/ **
MyClass is just an example class for demonstrating Reflection.
This code will be displayed as documentation for the class MyClass with Reflection.
* /
Class [class myclass] {
@@ /home/alex/public_html/devlink_draft/articles/docs/test.php 7-14
- Constants [0] {
}
- Static properties [0] {
}
- Static methods [0] {
}
- Properties [0] {
}
- Methods [1] {
/ **
And this is a comment to the constructor.
* /
Method [public method __construct] {
@@ /home/alex/public_html/devlink_draft/articles/docs/test.php 12 - 13
}
}
}
Часть 1 Object Oriented Programming (OOP) in PHP Interfaces, Classes, Abstract Classes, Objects
Часть 2 - Object Oriented Programming (OOP) in PHP Interfaces, Classes, Abstract
Comments
To leave a comment
Running server side scripts using PHP as an example (LAMP)
Terms: Running server side scripts using PHP as an example (LAMP)