cvs: ZendEngine2 /tests .cvsignore bug21478.phpt zend2.php zend2.php.txt

From: Date: Tue, 01 Jul 2003 15:56:08 +0000
Subject: cvs: ZendEngine2 /tests .cvsignore bug21478.phpt zend2.php zend2.php.txt
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-1418@lists.php.net to get a copy of this message
sniper Tue Jul 1 11:56:08 2003 EDT Added files: /ZendEngine2/tests .cvsignore zend2.php.txt Removed files: /ZendEngine2/tests zend2.php Modified files: /ZendEngine2/tests bug21478.phpt Log: Missing .cvsignore, broken test, renamed zend2.php -> zend2.php.txt Index: ZendEngine2/tests/bug21478.phpt diff -u ZendEngine2/tests/bug21478.phpt:1.1 ZendEngine2/tests/bug21478.phpt:1.2 --- ZendEngine2/tests/bug21478.phpt:1.1 Sun Jun 1 14:35:29 2003 +++ ZendEngine2/tests/bug21478.phpt Tue Jul 1 11:56:07 2003 @@ -1,36 +1,37 @@ ---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"); -?> ---EXPECT-- -Done. -THIS IS A TEST. +--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. Index: ZendEngine2/tests/.cvsignore +++ ZendEngine2/tests/.cvsignore phpt.* *.diff *.log *.exp *.out *.php test.txt Index: ZendEngine2/tests/zend2.php.txt +++ ZendEngine2/tests/zend2.php.txt 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(); ?>

« previous php.zend-engine.cvs (#1418) next »