From 15d583e6a38e7fcbe3aa14ff5625087334a4d0a1 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Mon, 24 May 2004 14:07:35 +0000 Subject: [PATCH] fix #27440 amd #27649 and some examples git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@159507 c90b9560-bf6c-de11-be94-00142212c4b1 --- appendices/migration5.xml | 140 +++----------------------------------- 1 file changed, 9 insertions(+), 131 deletions(-) diff --git a/appendices/migration5.xml b/appendices/migration5.xml index 7b38e76a5b..4cd5b64fc1 100755 --- a/appendices/migration5.xml +++ b/appendices/migration5.xml @@ -1,5 +1,5 @@ - + Migrating from PHP 4 to PHP 5 @@ -69,9 +69,6 @@ An object with no properties is no longer considered "empty". - - Classes must be declared before used. - @@ -105,29 +102,6 @@ if (!$t) { } ?> -]]> - - - - - The following example was valid in &php; 4, although it will produce a fatal - error in &php; 5. - - - - Classes must be declared before used - -barfu(); - -class fubar { - function barfu() { - echo 'fubar'; - } -} -?> ]]> @@ -1097,112 +1071,16 @@ echo "Foo::constant = " . Foo::constant . "\n"; exception = $exception; - } - - function Display() { - print "MyException: $this->exception\n"; - } -} - -class MyExceptionFoo extends MyException { - function __construct($exception) { - $this->exception = $exception; - } - - function Display() { - print "MyException: $this->exception\n"; - } -} - try { - throw new MyExceptionFoo('Hello'); -} -catch (MyException $exception) { - $exception->Display(); + throw new Exception('Hello'); } catch (Exception $exception) { - echo $exception; + echo $exception; } ?> ]]> - - Even though the above example shows that it is possible to define - exception classes that don't inherit from Exception it is best to do so. - This is because the internal Exception class can gather a lot of - information otherwise not available. The &php; code emulation code would - look something like shown below. The comments show the meaning of each - property and hence their getter methods. As the code shows it is possible - to read any available information by using the getter methods. But since - some of the methods are used internally they are marked final. All in all - the class is very restrictive because it must be ensured that anything - used internally always works as expected. - - - Base exceptions class - -message = $message; - } - $this->code = $code; - $this->file = __FILE__; // of throw clause - $this->line = __LINE__; // of throw clause - $this->trace = debug_backtrace(); - $this->string = StringFormat($this); - } - - protected $message = 'Unknown exception'; // exception message - protected $code = 0; // user defined exception code - protected $file; // source filename of exception - protected $line; // source line of exception - - private $trace; // backtrace of exception - private $string; // internal only!! - - final function getMessage() { - return $this->message; - } - final function getCode() { - return $this->code; - } - final function getFile() { - return $this->file; - } - final function getTrace() { - return $this->trace; - } - final function getTraceAsString() { - return self::TraceFormat($this); - } - function _toString() { - return $this->string; - } - static private function StringFormat(Exception $exception) { - // ... a function not available in PHP scripts - // that returns all relevant information as a string - } - static private function TraceFormat(Exception $exception) { - // ... a function not available in PHP scripts - // that returns the backtrace as a string - } -} -?> -]]> - - - - If you derive your exception classes from this Exception base class your - exceptions will be nicely shown in the built-in handler for uncaught - exceptions. - Old code that has no user-defined classes or functions 'catch', 'throw' and 'try' will run without modifications. @@ -1552,7 +1430,7 @@ foreach($obj as $key => $val) { // matches the following 7 lines with the for directive. $it = $obj->getIterator(); -for($it->rewind(); $it->hasMore(); $it->next) { +for($it->rewind(); $it->valid(); $it->next()) { $key = $it->current(); $val = $it->key(); echo "$key = $val\n"; @@ -1655,11 +1533,11 @@ class Foo { } } -reflection_class::export('Foo'); -reflection_object::export(new Foo); -reflection_method::export('Foo', 'func'); -reflection_property::export('Foo', 'prop'); -reflection_extension::export('standard'); +reflectionClass::export('Foo'); +reflectionObject::export(new Foo); +reflectionMethod::export('Foo', 'func'); +reflectionProperty::export('Foo', 'prop'); +reflectionExtension::export('standard'); ?> ]]>