diff options
author | SVN Migration <svn@php.net> | 2004-01-25 12:03:25 +0000 |
---|---|---|
committer | SVN Migration <svn@php.net> | 2004-01-25 12:03:25 +0000 |
commit | 22476b36ce621bdd115493bab84cbe706e422a7c (patch) | |
tree | 1124d1c5af68860a78c2252bb0dac63c9f18156e /Zend/tests | |
parent | eb7aca4ea896b09cb9afc2466a46f4720acc4a4e (diff) | |
download | php-git-php_ibase_before_split.tar.gz |
This commit was manufactured by cvs2svn to create tagphp_ibase_before_split
'php_ibase_before_split'.
Diffstat (limited to 'Zend/tests')
-rw-r--r-- | Zend/tests/bug19859.phpt | 22 | ||||
-rwxr-xr-x | Zend/tests/bug20240.phpt | 43 | ||||
-rwxr-xr-x | Zend/tests/bug20242.phpt | 26 | ||||
-rwxr-xr-x | Zend/tests/bug21478.phpt | 37 | ||||
-rwxr-xr-x | Zend/tests/bug21888.phpt | 39 | ||||
-rwxr-xr-x | Zend/tests/bug22725.phpt | 31 | ||||
-rw-r--r-- | Zend/tests/bug22836.phpt | 24 | ||||
-rw-r--r-- | Zend/tests/bug23104.phpt | 12 | ||||
-rwxr-xr-x | Zend/tests/bug24436.phpt | 24 | ||||
-rw-r--r-- | Zend/tests/bug24635.phpt | 30 | ||||
-rw-r--r-- | Zend/tests/bug24699.phpt | 13 | ||||
-rw-r--r-- | Zend/tests/bug24773.phpt | 9 | ||||
-rwxr-xr-x | Zend/tests/bug24884.phpt | 28 | ||||
-rw-r--r-- | Zend/tests/bug26010.phpt | 19 | ||||
-rwxr-xr-x | Zend/tests/bug26077.phpt | 9 | ||||
-rwxr-xr-x | Zend/tests/bug26166.phpt | 67 | ||||
-rwxr-xr-x | Zend/tests/bug26229.phpt | 21 | ||||
-rwxr-xr-x | Zend/tests/bug26281.phpt | 13 | ||||
-rwxr-xr-x | Zend/tests/bug26696.phpt | 22 | ||||
-rwxr-xr-x | Zend/tests/bug26697.phpt | 24 | ||||
-rwxr-xr-x | Zend/tests/bug26698.phpt | 71 | ||||
-rwxr-xr-x | Zend/tests/bug26801.phpt | 22 | ||||
-rwxr-xr-x | Zend/tests/bug26802.phpt | 49 | ||||
-rwxr-xr-x | Zend/tests/dtor_scope.phpt | 34 | ||||
-rw-r--r-- | Zend/tests/zend2.php.txt | 275 |
25 files changed, 0 insertions, 964 deletions
diff --git a/Zend/tests/bug19859.phpt b/Zend/tests/bug19859.phpt deleted file mode 100644 index d961b75a78..0000000000 --- a/Zend/tests/bug19859.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -Bug #19859 (__call() does not catch call_user_func_array() calls) ---SKIPIF-- -<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 is needed'); ?> ---FILE-- -<?php -class test -{ - function __call($method,$args) - { - print "test::__call invoked for method '$method'\n"; - } -} -$x = new test; -$x->fake(1); -call_user_func_array(array($x,'fake'),array(1)); -call_user_func(array($x,'fake'),2); -?> ---EXPECT-- -test::__call invoked for method 'fake' -test::__call invoked for method 'fake' -test::__call invoked for method 'fake' diff --git a/Zend/tests/bug20240.phpt b/Zend/tests/bug20240.phpt deleted file mode 100755 index acf673a277..0000000000 --- a/Zend/tests/bug20240.phpt +++ /dev/null @@ -1,43 +0,0 @@ ---TEST-- -Bug #20240 (order of destructor calls) ---SKIPIF-- -<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 is needed'); ?> ---FILE-- -<?php - -class test -{ - public $member; - - function test() { - $this->member = 1; - register_shutdown_function(array($this, 'destructor')); - } - - function destructor() { - print __METHOD__ . "\n"; - } - - function __destruct() { - print __METHOD__ . "\n"; - } - - function add() { - $this->member += 1; - print $this->member."\n"; - } -} - -$t = new test(); - -$t->add(); -$t->add(); - -echo "Done\n"; -?> ---EXPECT-- -2 -3 -Done -test::destructor -test::__destruct diff --git a/Zend/tests/bug20242.phpt b/Zend/tests/bug20242.phpt deleted file mode 100755 index bd140f5806..0000000000 --- a/Zend/tests/bug20242.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -Bug #20242 (Method call in front of class definition) ---SKIPIF-- -<?php if (version_compare(zend_version(), '2.0.0-dev', '>=')) die('skip ZendEngine 2 does not support this'); ?> ---FILE-- -<?php - -// THIS IS A WON'T FIX FOR ZE2 - -test::show_static(); - -$t = new test; -$t->show_method(); - -class test { - static function show_static() { - echo "static\n"; - } - function show_method() { - echo "method\n"; - } -} -?> ---EXPECT-- -static -method diff --git a/Zend/tests/bug21478.phpt b/Zend/tests/bug21478.phpt deleted file mode 100755 index 8b38f24d6e..0000000000 --- a/Zend/tests/bug21478.phpt +++ /dev/null @@ -1,37 +0,0 @@ ---TEST-- -Bug #21478 (Zend/zend_alloc.c :: shutdown_memory_manager produces segfault) ---SKIPIF-- -<?php - if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 is needed'); - if (!function_exists('stream_filter_register')) die('skip stream_filter_register() not available'); -?> ---FILE-- -<?php -class debugfilter extends php_user_filter { - function filter($in, $out, &$consumed, $closing) { - while ($bucket = stream_bucket_make_writeable($in)) { - $bucket->data = strtoupper($bucket->data); - stream_bucket_append($out, $bucket); - $consumed += strlen($bucket->data); - } - return PSFS_PASS_ON; - } -} - -stream_filter_register("myfilter","debugfilter"); - -$fp = fopen(dirname(__FILE__)."/test.txt","w"); -stream_filter_append($fp, "myfilter"); -stream_filter_append($fp, "myfilter"); -stream_filter_append($fp, "myfilter"); -fwrite($fp, "This is a test.\n"); -print "Done.\n"; -fclose($fp); -// Uncommenting the following 'print' line causes the segfault to stop occuring -// print "2\n"; -readfile(dirname(__FILE__)."/test.txt"); -unlink(dirname(__FILE__)."/test.txt"); -?> ---EXPECT-- -Done. -THIS IS A TEST. diff --git a/Zend/tests/bug21888.phpt b/Zend/tests/bug21888.phpt deleted file mode 100755 index 43b19c1e8b..0000000000 --- a/Zend/tests/bug21888.phpt +++ /dev/null @@ -1,39 +0,0 @@ ---TEST-- -Bug #21888 (protected property and protected method of the same name) ---SKIPIF-- -<?php - if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 is needed'); -?> ---FILE-- -<?php -class mom { - - protected $prot = "protected property\n"; - - protected function prot() { - print "protected method\n"; - } -} - -class child extends mom { - - public function callMom() { - $this->prot(); - } - - public function viewMom() { - print $this->prot; - } - -} - -$c = new child(); -$c->callMom(); -$c->viewMom(); -?> ---EXPECT-- -protected method -protected property ---EXPECT-- -protected method -protected property diff --git a/Zend/tests/bug22725.phpt b/Zend/tests/bug22725.phpt deleted file mode 100755 index aadd81be5a..0000000000 --- a/Zend/tests/bug22725.phpt +++ /dev/null @@ -1,31 +0,0 @@ ---TEST-- -bug #22725 (A derived class can call a parent's protected method that calls a private method) ---SKIPIF-- -<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> ---FILE-- -<?php -class Foo { - private function aPrivateMethod() { - echo "Foo::aPrivateMethod() called.\n"; - } - - protected function aProtectedMethod() { - echo "Foo::aProtectedMethod() called.\n"; - $this->aPrivateMethod(); - } -} - -class Bar extends Foo { - public function aPublicMethod() { - echo "Bar::aPublicMethod() called.\n"; - $this->aProtectedMethod(); - } -} - -$o = new Bar; -$o->aPublicMethod(); -?> ---EXPECT-- -Bar::aPublicMethod() called. -Foo::aProtectedMethod() called. -Foo::aPrivateMethod() called. diff --git a/Zend/tests/bug22836.phpt b/Zend/tests/bug22836.phpt deleted file mode 100644 index 14c9e9f3ed..0000000000 --- a/Zend/tests/bug22836.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -Bug #22836 (returning references to NULL) ---SKIPIF-- -<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 is needed'); ?> ---FILE-- -<?php -function &f() -{ - $x = "foo"; - var_dump($x); - print "'$x'\n"; - return ($a); -} -for ($i = 0; $i < 8; $i++) { - $h =& f(); -} -?> ---EXPECTF-- -string(3) "foo" -'foo' - -Notice: Undefined variable: a in %s on line %d - -Fatal error: Only variables or references can be returned by reference in %s on line %d diff --git a/Zend/tests/bug23104.phpt b/Zend/tests/bug23104.phpt deleted file mode 100644 index 04df3bdeb5..0000000000 --- a/Zend/tests/bug23104.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -Bug #23104 (Hash position not reset for constant arrays) ---FILE-- -<?php -function foo($bar = array("a", "b", "c")) -{ - var_dump(current($bar)); -} -foo(); -?> ---EXPECT-- -string(1) "a" diff --git a/Zend/tests/bug24436.phpt b/Zend/tests/bug24436.phpt deleted file mode 100755 index 0c261b668e..0000000000 --- a/Zend/tests/bug24436.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -Bug #24436 (isset()/empty() produce errors with non-existent variables in classes) ---SKIPIF-- -<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 is needed'); ?> ---INI-- -error_reporting=2047 ---FILE-- -<?php -class test { - function __construct() { - if (empty($this->test[0][0])) { print "test1\n";} - if (!isset($this->test[0][0])) { print "test2\n";} - if (empty($this->test)) { print "test1\n";} - if (!isset($this->test)) { print "test2\n";} - } -} - -$test1 = new test(); -?> ---EXPECT-- -test1 -test2 -test1 -test2 diff --git a/Zend/tests/bug24635.phpt b/Zend/tests/bug24635.phpt deleted file mode 100644 index d9466d971e..0000000000 --- a/Zend/tests/bug24635.phpt +++ /dev/null @@ -1,30 +0,0 @@ ---TEST-- -Bug #24635 (crash on dtor calling other functions) ---SKIPIF-- -<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 is needed'); ?> ---FILE-- -<?php -class SiteClass { - function __construct() { $this->page = new PageClass(); } -} -class PageClass { - function Display() { - $section = new SectionClass("PageClass::Display"); - } -} -class SectionClass { - function __construct($comment) { - $this->Comment = $comment; - } - function __destruct() { - out($this->Comment); // this line doesn't crash PHP - out("\n<!-- End Section: " . $this->Comment . "-->"); // this line - } -} -function out($code) { return; } -$site = new SiteClass(); -$site->page->Display(); -echo "OK\n"; -?> ---EXPECT-- -OK diff --git a/Zend/tests/bug24699.phpt b/Zend/tests/bug24699.phpt deleted file mode 100644 index 81ca4f5091..0000000000 --- a/Zend/tests/bug24699.phpt +++ /dev/null @@ -1,13 +0,0 @@ ---TEST-- -Bug #24699 (Memory Leak with per-class constants) ---SKIPIF-- -<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 is needed'); ?> ---FILE-- -<?php -class TEST { const FOO = SEEK_CUR; }; -class TEST2 { const FOO = 1; }; -class TEST3 { const FOO = PHP_VERSION; }; -print TEST::FOO."\n"; -?> ---EXPECT-- -1 diff --git a/Zend/tests/bug24773.phpt b/Zend/tests/bug24773.phpt deleted file mode 100644 index c0bb632f19..0000000000 --- a/Zend/tests/bug24773.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -Bug #24773 (unset() of integers treated as arrays causes a crash) ---FILE-- -<?php - $array = 'test'; - unset($array["lvl1"]["lvl2"]["b"]); -?> ---EXPECTF-- -Fatal error: Cannot unset string offsets in %s on line %d diff --git a/Zend/tests/bug24884.phpt b/Zend/tests/bug24884.phpt deleted file mode 100755 index 81bb3d6414..0000000000 --- a/Zend/tests/bug24884.phpt +++ /dev/null @@ -1,28 +0,0 @@ ---TEST-- -Bug #24884 (calling $this->__clone(); crashes php) ---SKIPIF-- -<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> ---FILE-- -<?php -class Test { - function __copy() - { - $string = PHP_VERSION; - $version = $string{0}; - if($string < 5) - { - return $this; - } - else - { - return $this->__clone(); - } - } -} -$test = new Test(); -$test2 = $test->__copy(); -var_dump($test2); -?> ---EXPECT-- -object(Test)#2 (0) { -} diff --git a/Zend/tests/bug26010.phpt b/Zend/tests/bug26010.phpt deleted file mode 100644 index a3c41faefc..0000000000 --- a/Zend/tests/bug26010.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -Bug #26010 (private / protected variables get exposed by get_object_vars()) ---FILE-- -<?php -class foo { - private $private = 'private'; - protected $protected = 'protected'; - public $public = 'public'; -} -$data = new foo(); -$obj_vars = get_object_vars($data); -var_dump($obj_vars); -?> ---EXPECT-- -array(1) { - ["public"]=> - string(6) "public" -} - diff --git a/Zend/tests/bug26077.phpt b/Zend/tests/bug26077.phpt deleted file mode 100755 index fa154655bf..0000000000 --- a/Zend/tests/bug26077.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -Bug #26077 Memory leaks when creating an instance of an object ---FILE-- -<?php -class foo {} new foo(); -?> -===DONE=== ---EXPECT-- -===DONE=== diff --git a/Zend/tests/bug26166.phpt b/Zend/tests/bug26166.phpt deleted file mode 100755 index 1c3934ac91..0000000000 --- a/Zend/tests/bug26166.phpt +++ /dev/null @@ -1,67 +0,0 @@ ---TEST-- -Bug #26166 (__toString() crash when no values returned) ---FILE-- -<?php -class Foo -{ - function __toString() - { - return "Hello World!\n"; - } -} - -class Bar -{ - private $obj; - - function __construct() - { - $this->obj = new Foo(); - } - - function __toString() - { - return $this->obj->__toString(); - } -} - -$o = new Bar; -echo $o; - -echo "===THROW===\n"; - -class Error -{ - function __toString() { - throw new Exception("This is an error!"); - } -} - -$o = new Error; -try { - echo $o; -} -catch (Exception $e) { - echo "Got the exception\n"; -} - -echo "===NONE===\n"; - -class None -{ - function __toString() { - } -} - -$o = new None; -echo $o; - -?> -===DONE=== ---EXPECTF-- -Hello World! -===THROW=== -Got the exception -===NONE=== - -Fatal error: Method None::__toString() must return a string value in %sbug26166.php on line %d diff --git a/Zend/tests/bug26229.phpt b/Zend/tests/bug26229.phpt deleted file mode 100755 index 1e03bb2c49..0000000000 --- a/Zend/tests/bug26229.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Bug #26229 (getIterator() segfaults when it returns arrays or scalars) ---FILE-- -<?php - -class array_iterator implements IteratorAggregate { - public function getIterator() { - return array('foo', 'bar'); - } -} - -$obj = new array_iterator; - -foreach ($obj as $property => $value) { - var_dump($value); -} -?> -===DONE=== ---EXPECTF-- -Warning: Objects returned by array_iterator::getIterator() must be traversable or implement interface Iterator in %sbug26229.php on line %d -===DONE===
\ No newline at end of file diff --git a/Zend/tests/bug26281.phpt b/Zend/tests/bug26281.phpt deleted file mode 100755 index a3a735a552..0000000000 --- a/Zend/tests/bug26281.phpt +++ /dev/null @@ -1,13 +0,0 @@ ---TEST-- -Bug #26281 (switch() crash when condition is a string offset) ---FILE-- -<?php - $x = 'abc'; - switch ($x{0}) { - case 'a': - echo "no crash\n"; - break; - } -?> ---EXPECT-- -no crash diff --git a/Zend/tests/bug26696.phpt b/Zend/tests/bug26696.phpt deleted file mode 100755 index ca2ea0910e..0000000000 --- a/Zend/tests/bug26696.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -Bug #26696 (crash in switch() when string index is used) ---FILE-- -<?php -$str = 'asdd/?'; -$len = strlen($str); -for ($i = 0; $i < $len; $i++) { - switch ($str[$i]) { - case '?': - echo "?\n"; - break; - default: - echo "x"; - break; - } -} - -?> -===DONE=== ---EXPECT-- -xxxxx? -===DONE===
\ No newline at end of file diff --git a/Zend/tests/bug26697.phpt b/Zend/tests/bug26697.phpt deleted file mode 100755 index 8266a23e34..0000000000 --- a/Zend/tests/bug26697.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -Bug #26697 (calling class_exists on a nonexistent class in __autoload results in segfault) ---SKIPIF-- -<?php if (function_exists('__autoload')) die('skip __autoload() declared in auto_prepend_file');?> ---FILE-- -<?php - -function __autoload($name) -{ - echo __METHOD__ . "($name)\n"; - var_dump(class_exists('NotExistingClass')); - echo __METHOD__ . "($name), done\n"; -} - -var_dump(class_exists('NotExistingClass')); - -?> -===DONE=== ---EXPECTF-- -__autoload(NotExistingClass) -bool(false) -__autoload(NotExistingClass), done -bool(false) -===DONE=== diff --git a/Zend/tests/bug26698.phpt b/Zend/tests/bug26698.phpt deleted file mode 100755 index c55cb596cd..0000000000 --- a/Zend/tests/bug26698.phpt +++ /dev/null @@ -1,71 +0,0 @@ ---TEST-- -Bug #26698 (Thrown exceptions while evaluting argument to pass as parameter crash PHP) ---FILE-- -<?php - -class Object -{ - function getNone() - { - throw new Exception('NONE'); - } -} - -class Proxy -{ - function three($a, $b, $c) - { - } - - function callOne() - { - try - { - $res = new Object(); - $this->three($res->getNone()); - } - catch(Exception $e) - { - echo 'Caught: '.$e->getMessage()."\n"; - } - } - - function callTwo() - { - try - { - $res = new Object(); - $this->three(1, $res->getNone()); - } - catch(Exception $e) - { - echo 'Caught: '.$e->getMessage()."\n"; - } - } - - function callThree() - { - try - { - $res = new Object(); - $this->three(1, 2, $res->getNone()); - } - catch(Exception $e) - { - echo 'Caught: '.$e->getMessage()."\n"; - } - } -} - -$p = new Proxy(); - -$p->callOne(); -$p->callTwo(); -$p->callThree(); -?> -===DONE=== ---EXPECT-- -Caught: NONE -Caught: NONE -Caught: NONE -===DONE=== diff --git a/Zend/tests/bug26801.phpt b/Zend/tests/bug26801.phpt deleted file mode 100755 index f81ea88c9c..0000000000 --- a/Zend/tests/bug26801.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -Bug #26801 (switch ($a{0}) crash) ---FILE-- -<?php - -$a = '11'; -$b = $a{0}; -switch ($b) { - case '-': - break; -} - -$a = '22'; -switch ($a{0}) { - case '-': - break; -} - -?> -===DONE=== ---EXPECT-- -===DONE=== diff --git a/Zend/tests/bug26802.phpt b/Zend/tests/bug26802.phpt deleted file mode 100755 index 794dbd73b4..0000000000 --- a/Zend/tests/bug26802.phpt +++ /dev/null @@ -1,49 +0,0 @@ ---TEST-- -Bug #26802 (Can't call static method using a variable) ---FILE-- -<?php - -function func() { - echo __METHOD__ . "\n"; -} - -function work() { - echo __METHOD__ . "\n"; -} - -$function = 'func'; -$function(); - -class foo -{ - static $method = 'func'; - - static public function bar() { - echo __METHOD__ . "\n"; - } - - static public function func() { - echo __METHOD__ . "\n"; - } -} - -foo::bar(); - -$static_method = "foo::bar"; - -$static_method(); - -/* The following is a BC break with PHP 4 where it would - * call foo::fail. In PHP 5 we first evaluate static class - * properties and then do the function call. - */ -$method = 'fail'; -foo::$method(); -?> -===DONE=== ---EXPECT-- -func -foo::bar -foo::bar -func -===DONE=== diff --git a/Zend/tests/dtor_scope.phpt b/Zend/tests/dtor_scope.phpt deleted file mode 100755 index ab991cf949..0000000000 --- a/Zend/tests/dtor_scope.phpt +++ /dev/null @@ -1,34 +0,0 @@ ---TEST-- -Scoping in destructor call ---SKIPIF-- -<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> ---FILE-- -<?php - class T - { - private $var = array(); - - public function add($a) - { - array_push($this->var, $a); - } - - public function __destruct() - { - print_r($this->var); - } - } - - class TT extends T - { - } - $t = new TT(); - $t->add("Hello"); - $t->add("World"); -?> ---EXPECT-- -Array -( - [0] => Hello - [1] => World -) diff --git a/Zend/tests/zend2.php.txt b/Zend/tests/zend2.php.txt deleted file mode 100644 index afe422eaae..0000000000 --- a/Zend/tests/zend2.php.txt +++ /dev/null @@ -1,275 +0,0 @@ -Example 1: A singleton (static members) -======================================= - -<?php - - class Counter { - var $counter = 0; - - function increment_and_print() - { - print ++$this->counter; - print "\n"; - } - } - - - class SingletonCounter { - static $m_instance = NULL; - - function Instance() - { - if (self::$m_instance == NULL) { - self::$m_instance = new Counter(); - } - return self::$m_instance; - } - } - - SingletonCounter::Instance()->increment_and_print(); - SingletonCounter::Instance()->increment_and_print(); - SingletonCounter::Instance()->increment_and_print(); - -?> - -Example 2: Factory method (derefencing objects returned from functions) -======================================================================= - -<?php - - class Circle { - function draw() - { - print "Circle\n"; - } - } - - class Square { - function draw() - { - print "Square\n"; - } - } - - function ShapeFactoryMethod($shape) - { - switch ($shape) { - case "Circle": - return new Circle(); - case "Square": - return new Square(); - } - } - - ShapeFactoryMethod("Circle")->draw(); - ShapeFactoryMethod("Square")->draw(); - - -?> - -Example 3: Class constants and class scope -========================================== - -<?php - - class ErrorCodes { - const FATAL = "Fatal error\n"; - const WARNING = "Warning\n"; - const INFO = "Informational message\n"; - - function print_fatal_error_codes() - { - print "FATAL = " . FATAL; - print "self::FATAL = " . self::FATAL; - } - } - - /* Call the static function and move into the ErrorCodes scope */ - ErrorCodes::print_fatal_error_codes(); - -?> - -Example 4: Regular object method using both local and global functions -====================================================================== - -<?php - - class HelloWorld { - const HELLO_WORLD = "Hello, World!\n"; - - function get_hello_world() - { - return HELLO_WORLD; - } - - function length_of_hello_world() - { - $str = $this->get_hello_world(); - return strlen($str); - } - } - - $obj = new HelloWorld(); - print "length_of_hello_world() = " . $obj->length_of_hello_world(); - print "\n"; -?> - -Example 5: Multiple derefencing of objects returned from methods -================================================================ - -<?php - - - class Name { - function Name($_name) - { - $this->name = $_name; - } - - function display() - { - print $this->name; - print "\n"; - } - } - - class Person { - function Person($_name, $_address) - { - $this->name = new Name($_name); - } - - function getName() - { - return $this->name; - } - } - - $person = new Person("John", "New York"); - $person->getName()->display(); - -?> - -Example 6: Exception handling -============================= - -<? - class MyException { - function MyException($_error) { - $this->error = $_error; - } - - function getException() - { - return $this->error; - } - } - - function ThrowException() - { - throw new MyException("'This is an exception!'"); - } - - - try { - } catch (MyException $exception) { - print "There was an exception: " . $exception->getException(); - print "\n"; - } - - try { - ThrowException(); - } catch (MyException $exception) { - print "There was an exception: " . $exception->getException(); - print "\n"; - } - -?> - -Example 7: __clone() -=================== - -<? - class MyCloneable { - static $id = 0; - - function MyCloneable() - { - $this->id = self::$id++; - } - - function __clone() - { - $this->name = $that->name; - $this->address = "New York"; - $this->id = self::$id++; - } - } - - - - $obj = new MyCloneable(); - - $obj->name = "Hello"; - $obj->address = "Tel-Aviv"; - - print $obj->id; - print "\n"; - - $obj = $obj->__clone(); - - print $obj->id; - print "\n"; - print $obj->name; - print "\n"; - print $obj->address; - print "\n"; -?> - -Example 8: Unified constructors -=============================== - -<? - - class BaseClass { - function __construct() - { - print "In BaseClass constructor\n"; - } - } - - class SubClass extends BaseClass { - function __construct() - { - parent::__construct(); - print "In SubClass constructor\n"; - } - } - - $obj = new BaseClass(); - - $obj = new SubClass(); - -?> - -Example 9: Destructors -======================= - -<?php - -class MyDestructableClass { - function __construct() - { - print "In constructor\n"; - $this->name = "MyDestructableClass"; - } - - function __destruct() - { - print "Destroying " . $this->name . "\n"; - } -} - -$obj = new MyDestructableClass(); - -?> |