|
|
|
PHP
3.0
is rewritten from the ground up. It has a proper parser that
is much more robust and consistent than 2.0's. 3.0 is also
significantly faster, and uses less memory. However, some
of these improvements have not been possible without compatibility
changes, both in syntax and functionality.
In
addition, PHP's developers have tried to clean up both PHP's
syntax and semantics in version 3.0, and this has also caused
some incompatibilities. In the long run, we believe that these
changes are for the better.
This
chapter
will try to guide you through the incompatibilities you might
run into when going from PHP/FI 2.0 to PHP 3.0 and help you
resolve them. New features are not mentioned here unless necessary.
A
conversion program that can automatically convert your old
PHP/FI 2.0 scripts exists. It can be found in the convertor
subdirectory of the PHP 3.0 distribution. This program only
catches the syntax changes though, so you should read this
chapter carefully anyway.
|
|
Memory
Management
in Functions Any memory needed by a function should be allocated
with either emalloc() or estrdup(). These are memory handling
abstraction functions that look and smell like the normal malloc()
and strdup() functions. Memory should be freed with efree().
There are two kinds of memory in this program: memory which
is returned to the parser in a variable, and memory which you
need for temporary storage in your internal function. When you
assign a string to a variable which is returned to the parser
you need to make sure you first allocate the memory with either
emalloc() or estrdup(). This memory should NEVER be freed by
you, unless you later in the same function overwrite your original
assignment (this kind of programming practice is not good though).
For any temporary/permanent memory you need in your functions/library
you should use the three emalloc(), estrdup(), and efree() functions.
They behave EXACTLY like their counterpart functions. Anything
you emalloc() or estrdup() you have to efree() at some point
or another, unless it's supposed to stick around until.
|
|