Faltu Funda| 30 Mar 2008 | |||||
|---|---|---|---|---|---|
|
practice interviews and prepare for interviews in todays changing world every one want to increase there salaries very quickly. Changes your employer is an very efficient solution for this. But changing employer and company is not so easy. cont.. |
||||
| 27 Feb 2008 | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Changes in php5 whats new in php5 There are lot's of new changes made in php5 as compared to php4. So, we'll discuss them here step by step. First we'll see difference in oops model. So what were some of the limitations in PHP 3 and 4? The biggest limitation (which led to further limitations) was the fact that the copy semantics of objects were the same as for native types. So how did this actually affect the PHP developer? When you'd assign a variable (that points to an object) to another variable, a copy of the object would be created. Not only did this impact performance but it usually also lead to obscure behavior and bugs in PHP 4 applications because many developers thought that both variables would be pointing at the same object which wasn't the case. They were pointing at separate copies of the same object, changing one would not change the other. For example:
In PHP 4, this piece of code would print out This behavior is not very intuitive, as many developers would expect the Java-like behavior. In Java variables actually hold a handle (or pointers) to the object, and therefore, when it is copied only the handle and not the entire object is duplicated. The old object model not only led to the above-mentioned problems but also led to fundamental problems that prevented implementing some additional features on top of the existing object model. In PHP 5, the infrastructure of the object model was rewritten to work with object handles. Unless you explicitly clone an object by using the Note: Passing by reference and assigning by reference is still supported, in case you want to actually change a variable's content (whether object or other type). New Object Oriented FeaturesThe new object oriented features are too numerous to give a detailed description in this section. The object oriented language chapter goes over each feature in detail. The following is a list of the main new features: 1. public/private/protected access modifiers for methods and propertiesAllows the use of common OO access modifiers to control access to methods and properties.
2. Unified constructor name __construct() Instead of the constructor being the name of the class, it should now be declared as
3. Object destructor support by defining a __destructor() methodAllows defining a destructor function that runs when an object is destroyed.
4. InterfacesGives the ability for a class to fulfill more than one is-a relationships. A class can inherit from one class only but may implement as many interfaces as it wants.
5. instanceof operator Language level support for is-a relationship checking. The PHP 4
6. final methods The
7. final classes After declaring a class as
8. Explicit object cloning In order to clone an object you have to use the
9. Class constantsClasses definitions can now include constant values, and are referenced using the class.
10. Static membersClasses definitions can now include static members (properties), accessible via the class. Common usage of static members is in the Singleton pattern.
11. Static methods You can now define methods as static allowing them to be called from non-object context. Static methods don't define the
12. abstract classes A class may be declared as
13. abstract methods A method may be declared as
14. Class type hintsFunction declarations may include class type hints for their parameters. If the functions are called with an incorrect class type an error occurs.
15. Support for dereferencing objects which are returned from methods.In PHP 4, you could not directly dereference objects which are returned from methods. You would have to first assign the object to a dummy variable and then dereference it.
PHP 5:
16. Iterators PHP 5 allows both PHP classes and PHP extension classes to implement an Iterator interface. Once you implement this interface you will be able to iterate instances of the class by using the
For a more complete example, please refer to the "Advanced OOP & Design Patterns" chapter. 17. __autoload() Many developers writing object-oriented applications create one PHP source file per-class definition. One of the biggest annoyances is having to write a long list of needed includes at the beginning of each script (one for each class). In PHP 5, this is no longer necessary. You may define an function __autoload($class_name) { |
||||||||||||||||||||||||
|
||||||||||||
1