©
本文档使用 PHP中文网手册 发布
Although most existing PHP 5 code should work without changes, you should pay attention to the following backward incompatible changes:
NULL
when passed
incompatible arguments as of PHP 5.2.1.
TRUE
on success as of PHP 5.2.1.
TRUE
on success as of PHP 5.2.1.
FALSE
.
As of PHP 5.2.0, this operation will emit an E_WARNING
,
as is the case in all other instances where division by zero is performed.
<?php
print 10 % 0 ;
?>
<?php
class foo {}
$foo = new foo ;
print $foo ;
?>
<?php
class foo {
public function __toString () {
throw new Exception ;
}
}
try {
print new foo ;
} catch( Exception $e ) {}
?>
<?php
abstract class foo {
abstract static function bar ();
}
?>
<?php
include "data:;base64,PD9waHAgcGhwaW5mbygpOz8+" ;
?>
Example #2 Object Oriented Code in PHP Core
<?php
interface foo {
}
class bar implements foo , foo {
}
class foo {
public $bar ;
function __get ( $var )
{
return $this -> bar ;
}
}
$foo = new foo ;
$bar =& $foo -> prop ;
class foo implements iterator {
public function current () {
}
public function next () {
}
public function key () {
}
public function valid () {
}
public function rewind () {
}
}
$foo = new foo ();
foreach( $foo as & $ref ) {}
class foo {
private function __construct () {
}
}
class bar extends foo {
public function __construct () {
parent :: __construct ();
}
}
new bar ;
stream_filter_register ( "" , "class" );
stream_filter_register ( "filter" , "" );
?>
Example #3 In the bzip2 Extension
<?php
bzopen ( "" , "w" );
bzopen ( "foo" , "a" );
$fp = fopen ( "foo" , "w" );
bzopen ( $fp , "r" );
?>
Example #4 In the datetime Extension
<?php
strtotime ( "today" , "now" );
new DateTime (new stdclass );
?>
Example #5 In the dBase Extension
<?php
dbase_open ( "foo" , - 1 );
dbase_open ( "foo" , null );
?>
Example #6 In the mcrypt Extension
<?php
$key = "this is a secret key" ;
$td = mcrypt_module_open ( 'tripledes' , '' , 'ecb' , '' );
$iv = mcrypt_create_iv ( mcrypt_enc_get_iv_size ( $td ),
MCRYPT_RAND );
mcrypt_generic_init ( $td , $key , $iv );
$encrypted_data = mcrypt_generic ( $td , "" );
?>
Example #7 In the oci8 Extension
<?php
oci_connect ( "user" , "pass" , "db" , "bogus_charset" );
$oci = oci_connect ( "user" , "pass" , "db" );
oci_password_change ( $oci , "" , "old" , "new" );
oci_password_change ( $oci , "user" , "" , "new" );
oci_password_change ( $oci , "user" , "old" , "" );
?>
Example #8 In the SPL Extension
<?php
$obj = new SplFileObject ( __FILE__ );
$obj -> fgetcsv ( "foo" );
$obj -> fgetcsv ( "," , "foo" );
?>
Example #9 In the Semaphore (sysvmsg) extension
<?php
?>
Example #10 A 5.2.1+ Zip Example
<?php
$obj = new ZipArchive ();
$obj -> open ( 'archive.zip' );
$obj -> setCommentName ( '' , 'comment' );
$obj -> getCommentName ( '' );
?>