Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:20003 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72763 invoked by uid 1010); 15 Nov 2005 16:19:06 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 72748 invoked from network); 15 Nov 2005 16:19:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Nov 2005 16:19:06 -0000 X-Host-Fingerprint: 192.38.9.232 gw2.emini.dk Linux 2.4/2.6 Received: from ([192.38.9.232:5598] helo=gw2.emini.dk) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id DE/18-07637-97A0A734 for ; Tue, 15 Nov 2005 11:19:06 -0500 Received: from foxbox (client-207-p-1-lns.glfd.dial.virgin.net [81.103.144.206]) by gw2.emini.dk (Postfix) with ESMTP id 7AA0A8E98D for ; Tue, 15 Nov 2005 17:18:47 +0100 (CET) Message-ID: <099001c5ea00$3eecc0d0$52906751@foxbox> Reply-To: "Steph Fox" To: "internals" Date: Tue, 15 Nov 2005 16:18:22 -0000 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_098D_01C5EA00.32F36A40" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1506 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 Subject: Upgrade notes for 5.1 From: steph@zend.com ("Steph Fox") ------=_NextPart_000_098D_01C5EA00.32F36A40 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi all, I've already canvassed Ilia and Stas - can anyone else think of anything I've missed/mis-explained here? Thanks guys/guyess, - Steph ------=_NextPart_000_098D_01C5EA00.32F36A40 Content-Type: text/plain; name="second_draft_upgrade_notes.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="second_draft_upgrade_notes.txt" UPGRADE NOTES - PHP 5.1=0A= =0A= 1. Changes in reference handling=0A= a. Overview=0A= b. Code that worked under PHP 4.3, but now fails=0A= c. Code that was valid under PHP 4.3, but now throws an error=0A= d. Code that failed under PHP 4.3, but now works=0A= e. Code that 'should have worked' under PHP 5.0=0A= f. Warnings that came and went=0A= 2. Reading []=0A= 3. instanceof, is_a(), is_subclass_of(), catch=0A= 4. MySQL support=0A= 5. SQLite support=0A= 6. Further migration information=0A= =0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=0A= =0A= 1. Reference handling=0A= =0A= Overview=0A= =3D=3D=3D=3D=3D=3D=3D=3D=0A= =0A= From the PHP script writer's point of view, the change most likely to = impact=0A= legacy code is in the way that references are handled in all PHP versions=0A= post-dating the PHP 4.4.0 release.=0A= =0A= Until and including PHP 4.3, it was possible to send, assign or return = variables=0A= by reference that should really be returned by value, such as a = constant, a=0A= temporary value (e.g. the result of an expression), or the result of a = function=0A= that had itself been returned by value, as here:=0A= =0A= =0A= =0A= Although this code would usually work as expected under PHP 4.3, in the = general=0A= case the result is undefined. The Zend Engine could not act correctly on = these=0A= values as references. This bug could and did lead to various = hard-to-reproduce=0A= memory corruption problems, particularly where the code base was large.=0A= =0A= In PHP 4.4.0, PHP 5.0.4 and all subsequent PHP releases, the Engine was = fixed=0A= to 'know' when the reference operation is being used on a value that = should=0A= not be referenced. The actual value is now used in such cases, and a = warning=0A= is emitted. The warning takes the form of an E_NOTICE in PHP 4.4.0 and = up,=0A= and E_STRICT in PHP 5.0.4 and up.=0A= =0A= Code that could potentially produce memory corruption can no longer do = so.=0A= However, some legacy code might work differently as a result.=0A= =0A= Code that worked under PHP 4.3, but now fails=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= =0A= =0A= Running the above script under any version of PHP that pre-dates the = reference=0A= fix would produce this output:=0A= =0A= array(3) {=0A= [0]=3D>=0A= &string(1) "a"=0A= [1]=3D>=0A= &string(1) "b"=0A= [2]=3D>=0A= &string(1) "c"=0A= }=0A= =0A= Following the reference fix, the same code would result in:=0A= =0A= array(3) {=0A= [0]=3D>=0A= &string(1) "c"=0A= [1]=3D>=0A= &string(1) "c"=0A= [2]=3D>=0A= &string(1) "c"=0A= }=0A= =0A= This is because, following the changes, func() assigns by value. The = value=0A= of $y is re-assigned, and reference-binding is preserved from $z. Prior=0A= to the fix, the value was assigned by reference, leading $y to be=0A= re-bound on each assignment. The attempt to bind to a temporary value=0A= by reference was the cause of the memory corruption.=0A= =0A= Such code can be made to work identically in both the pre-fix and the=0A= post-fix PHP versions. The signature of func() can be altered to return=0A= by reference, or the reference assignment can be removed from the result=0A= of func().=0A= =0A= =0A= =0A= In PHP 4.3 $x would be 'original value', whereas after the changes it = would=0A= be 'function return' - remember that where the function does not return = by=0A= reference, the reference assignment is converted to a regular assignment.=0A= Again, this can be brought to a common base, either by forcing func() to=0A= return by reference or by eliminating the by-reference assignment.=0A= =0A= Code that was valid under PHP 4.3, but now throws an error=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=0A= =0A= getThis();=0A= }=0A= }=0A= =0A= $bar =3D new Foo();=0A= $bar->destroyThis();=0A= var_dump($bar);=0A= =0A= ?>=0A= =0A= In PHP 5.0.3, $bar evaluated to NULL instead of returning an object.=0A= That happened because getThis() returns by value, but the value here=0A= is assigned by reference. Although it now works in the expected way,=0A= this is actually invalid code which will throw an E_NOTICE under=0A= PHP 4.4 or an E_STRICT under PHP 5.0.4 and up.=0A= =0A= Code that failed under PHP 4.3, but now works=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= =0A= =0A= =0A= In PHP 4.3 the third call to var_dump produces NULL, due to the memory=0A= corruption caused by returning an uninitialized value by reference.=0A= This is valid code in PHP 5.0.4 and up, but threw errors in earlier=0A= releases of PHP.=0A= =0A= array('alfa' =3D> 'ok'));=0A= $arr =3D& $arr['a1'];=0A= echo '-'.$arr['alfa']."-\n";=0A= =0A= ?>=0A= =0A= Until PHP 5.0.5, it wasn't possible to assign an array element by=0A= reference in this way. It now is.=0A= =0A= Code that 'should have worked' under PHP 5.0=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= =0A= There are a couple of instances of bugs reported under PHP 5.0 prior=0A= to the reference fixes which now 'work'. However, in both cases errors=0A= are thrown by PHP 5.1, because the code was invalid in the first place.=0A= Returning values by reference using self:: now works in the general=0A= case but throws an E_STRICT warning, and although your mileage may=0A= vary when assigning by reference to an overloaded object, you will=0A= still see an E_ERROR when you try it, even where the assignment=0A= itself appears to work.=0A= =0A= Warnings that came and went=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=0A= =0A= =0A= =0A= Nested calls to functions returning by reference are valid code under = both=0A= PHP 4.3 and PHP 5.1, but threw an unwarranted E_NOTICE or E_STRICT under=0A= the intervening PHP releases.=0A= =0A= 2. Reading []=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= =0A= test_ref($ar[]);=0A= var_dump($ar);=0A= $this->test($ar[]);=0A= }=0A= }=0A= =0A= $o =3D new XmlTest();=0A= $o->run();=0A= =0A= ?>=0A= =0A= This should always have thrown a fatal E_ERROR, because [] cannot be=0A= used for reading. It is invalid code in PHP 4.4.2 and PHP 5.0.5 upward.=0A= =0A= 3. instanceof, is_a(), is_subclass_of(), catch=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= =0A= In PHP 5.0, is_a() was deprecated and replaced by the "instanceof" = operator.=0A= There were some issues with the initial implementation of "instanceof", = which=0A= relied on __autoload() to search for missing classes. If the class was = not=0A= present, "instanceof" would throw a fatal E_ERROR due to the failure of=0A= __autoload() to discover that class. The same behaviour occurred in the=0A= "catch" operator and the is_subclass_of() function, for the same reason.=0A= =0A= None of these functions or operators call __autoload() in PHP 5.1, and=0A= the workarounds used in PHP 5.0 are no longer necessary.=0A= =0A= 4. MySQL support=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= =0A= In PHP 4, MySQL 3 support was built-in. With the release of PHP 5.0 there=0A= were two MySQL extensions, named 'mysql' and 'mysqli', which were = designed=0A= to support MySQL < 4.1 and MySQL 4.1 and up, respectively. PHP 5.1 = introduces=0A= PHP Data Objects, or PDO, which provides a very fast interface to all the=0A= database APIs supported by PHP. It is strongly recommended that you use = PDO and=0A= the PDO_MYSQL database driver, which can support any of the current = versions=0A= (MySQL 3, 4 or 5) in new PHP code, depending on the MySQL library = version used=0A= during compilation. The older extensions remain in place for reasons of = back=0A= compatibility, but are not enabled by default.=0A= =0A= 5. SQLite support=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= =0A= In PHP 5.0, SQLite 2 support was built-in. Due to the advent of SQLite 3=0A= and PHP Data Objects, the SQLite engine is no longer statically built = into=0A= PHP by default. The PDO_SQLITE driver communicates with the SQLite 3 = engine,=0A= and the sqlite extension remains in place only for reasons of back = compatibility.=0A= Note that the sqlite extension is now reliant on PDO under win32. The = intention=0A= is to allow support for legacy SQLite 2 code alongside newly written = SQLite 3=0A= code; the PDO, sqlite and PDO_SQLITE extensions should all be enabled. = PDO_SQLITE=0A= also supports SQLite 2, and can be used to communicate with either = SQLite 2=0A= and SQLite 3 via the DSN (Data Source Name) specified in = PDO::__construct().=0A= =0A= 6. Further migration information=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=0A= =0A= For general information about migrating from PHP 4 to PHP 5, please = refer to=0A= the relevant section in the PHP manual at = http://www.php.net/manual/migration5.php.=0A= ------=_NextPart_000_098D_01C5EA00.32F36A40--