|
| 1 | +Improvements |
| 2 | +------------ |
| 3 | + |
| 4 | +Zend was designed from the ground up for increased speed, |
| 5 | +reduced memory consumption and more reliable execution. We dare |
| 6 | +say it meets all of these goals and does so pretty well. Beyond |
| 7 | +that, there are several improvements in the language engine |
| 8 | +features: |
| 9 | + |
| 10 | +* References support. $foo = &$a; would make $foo and $a be two |
| 11 | + names to the same variable. This works with arrays as well, |
| 12 | + on either side; e.g., $foo = &$a[7]; would make $foo and $a[7] |
| 13 | + be two names to the same variable. Changing one would change |
| 14 | + the other and vice versa. |
| 15 | +* Object overloading support. This feature allows various OO |
| 16 | + libraries to use the OO notation of PHP to access their |
| 17 | + functionality. Right now, no use is made of that feature, |
| 18 | + but we'd have a COM module ready by the time PHP 4.0 is released. |
| 19 | + A CORBA module would probably follow. |
| 20 | +* include() and eval() are now functions, and not statements. |
| 21 | + That means they return a value. The default return value from |
| 22 | + include() and eval() is 1, so that you can do if (include()) |
| 23 | + without further coding. The return value may be changed by |
| 24 | + returning a value from the global scope of the included file |
| 25 | + or the evaluated string. For example, if 'return 7;' is executed |
| 26 | + in the global scope of foo.inc, include("foo.inc") would evaluate |
| 27 | + to 7. |
| 28 | +* Automatic resource deallocation. Several people have been bitten |
| 29 | + by the fact that PHP 3.0 had no concept of reference counting. |
| 30 | + Zend adds full reference counting for every value in the system, |
| 31 | + including resources. As soon as a resource is no longer referenced |
| 32 | + from any variable, it is automatically destroyed to save memory |
| 33 | + and resources. The most obvious example for the advantage in this |
| 34 | + is a loop that has an SQL query inside it, something like |
| 35 | + '$result = sql_query(...);'. In PHP 3.0, every iteration resulted |
| 36 | + in another SQL result-set allocated in the memory, and all of the |
| 37 | + result sets weren't destroyed until the end of the script's execution. |
| 38 | + In Zend, as soon as we overwrite an old result set with a new one, |
| 39 | + the old result set which is no longer referenced, is destroyed. |
| 40 | +* Full support for nesting arrays and objects within each other, in |
| 41 | + as many levels as you want. |
| 42 | +* Boolean type. true and false are now constants of type boolean. |
| 43 | + Comparing any other value to them would convert that value to a |
| 44 | + boolean first, and conduct the comparison later. That means, for |
| 45 | + example, that 5==true would evaluate to true (in PHP 3.0, true |
| 46 | + was nothing but a constant for the integer value of 1, so 5==true |
| 47 | + was identical to 5==1, which was false). |
| 48 | +* Runtime binding of function names. This complex name has a simple |
| 49 | + explanation - you can now call functions before they're declared! |
| 50 | +* Added here-docs support. |
| 51 | +* Added foreach. Two syntaxes supported: |
| 52 | + foreach($val in array_expr) statement |
| 53 | + foreach($key, $val in array_expr) statement |
| 54 | +* A true unset() implementation. A variable or element that is unset(), is now |
| 55 | + sent to oblivion in its entirely, no trace remains from it. |
| 56 | +* Output buffering support! Use ob_start() to begin output buffering, ob_end_flush() |
| 57 | + to end buffering and send out the buffered contents, ob_end_clean() to end buffering |
| 58 | + without sending the buffered contents, and ob_get_contents() to retreive the current |
| 59 | + contents of the output buffer. |
| 60 | + Header information (header(), content type, cookies) are not buffered. By turning |
| 61 | + on output buffering, you can effectively send header information all throughout your |
| 62 | + file, regardless of whether you've emitted body output or not. |
| 63 | +* Full variable reference within quoted strings: |
| 64 | + ${expr} - full indirect reference support for scalar variables |
| 65 | + {variable} - full variable support |
| 66 | + For example: |
| 67 | + $foo[5]["bar"] = "foobar"; |
| 68 | + print "{$foo[5]["bar"]}"; // would print "foobar" |
| 69 | +* Ability to call member functions of other classes from within member functions or from |
| 70 | + the global scope. You can now, for example, override a parent function with a child function, |
| 71 | + and call the parent function from it. |
| 72 | +* Runtime information for classes (class name, parent, available functions, etc.). |
| 73 | +* Much more efficient syntax highlighter - runs much quicker, performs more reliably, and |
| 74 | + generates much tighter HTML. |
| 75 | +* A full-featured debugger has been integrated with the language (supports breakpoints, |
| 76 | + expression evaluation, step-in/over, function call backtrace, and more). |
| 77 | + |
| 78 | + |
| 79 | +Incompatabilities |
| 80 | +----------------- |
| 81 | + |
| 82 | +Zend claims 100% compatability with the engine of PHP 3.0, and is |
| 83 | +shamelessly lying about it. Here's why: |
| 84 | + |
| 85 | +* static variable initializers only accept scalar values |
| 86 | + (in PHP 3.0 they accepted any valid expression). The impact |
| 87 | + should be somewhere in between void and non existant, since |
| 88 | + initializing a static variable with anything but a simple |
| 89 | + static value makes no sense at all. |
| 90 | + |
| 91 | +* The scope of break and continue is local to that of an |
| 92 | + include()'d file or an eval()'d string. The impact should |
| 93 | + be somewhat smaller of the one above. |
| 94 | + |
| 95 | +* return statement from a require()'d file no longer works. It |
| 96 | + hardly worked in PHP 3.0, so the impact should be fairly small. |
| 97 | + If you want this functionality - use include() instead. |
| 98 | + |
| 99 | +* unset() is no longer a function, but a statement. It was never |
| 100 | + documented as a function so the impact should be no bigger than |
| 101 | + nada. |
| 102 | + |
| 103 | +* The following letter combination is not supported within encapsulated |
| 104 | + strings: "{$". If you have a string that includes this letter |
| 105 | + combination, for example, print "{$somevar"; (which printed the |
| 106 | + letter { and the contents of the variable $somevar in PHP 3.0), |
| 107 | + it will result in a parse error under Zend. In this case, you |
| 108 | + would have to change the code to print "\{$somevar"; |
| 109 | + This incompatability is due to the full variable reference |
| 110 | + within quoted strings feature added in Zend. |
| 111 | + |
0 commit comments