define('PEAR_INSTALL_DIR', '@PEAR_INSTALLDIR@');
define('PEAR_EXTENSION_DIR', '@EXTENSION_DIR@');
+if (substr(PHP_OS, 0, 3) == 'WIN') {
+ define('OS_WINDOWS', true);
+ define('OS_UNIX', false);
+ define('PEAR_OS', 'Windows');
+} else {
+ define('OS_WINDOWS', false);
+ define('OS_UNIX', true);
+ define('PEAR_OS', 'Unix'); // blatant assumption
+}
+
$_PEAR_default_error_mode = PEAR_ERROR_RETURN;
$_PEAR_default_error_options = E_USER_NOTICE;
$_PEAR_default_error_callback = '';
* $_PEAR_destructor_object_list for destructor emulation if a
* destructor object exists.
*/
- function PEAR() {
- if (method_exists($this, "_".get_class($this))) {
- global $_PEAR_destructor_object_list;
- $_PEAR_destructor_object_list[] = &$this;
- }
+ function PEAR()
+ {
+ $classname = get_class($this);
if ($this->_debug) {
- printf("PEAR constructor called, class=%s\n",
- get_class($this));
+ print "PEAR constructor called, class=$classname\n";
+ }
+ while ($classname) {
+ $destructor = "_$classname";
+ if (method_exists($this, $destructor)) {
+ global $_PEAR_destructor_object_list;
+ $_PEAR_destructor_object_list[] = &$this;
+ break;
+ } else {
+ $classname = get_parent_class($classname);
+ }
}
}
// {{{ _PEAR_call_destructors()
-function _PEAR_call_destructors() {
+function _PEAR_call_destructors()
+{
global $_PEAR_destructor_object_list;
- if (is_array($_PEAR_destructor_object_list) && sizeof($_PEAR_destructor_object_list)) {
- reset($_PEAR_destructor_object_list);
- while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
- $destructor = "_".get_class($objref);
- if (method_exists($objref, $destructor)) {
- $objref->$destructor();
+ if (is_array($_PEAR_destructor_object_list) &&
+ sizeof($_PEAR_destructor_object_list))
+ {
+ reset($_PEAR_destructor_object_list);
+ while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
+ $classname = get_class($objref);
+ while ($classname) {
+ $destructor = "_$classname";
+ if (method_exists($objref, $destructor)) {
+ $objref->$destructor();
+ break;
+ } else {
+ $classname = get_parent_class($classname);
+ }
+ }
}
- }
- // Empty the object list to ensure that destructors are
- // not called more than once.
- $_PEAR_destructor_object_list = array();
+ // Empty the object list to ensure that destructors are
+ // not called more than once.
+ $_PEAR_destructor_object_list = array();
}
}
}
}
-print "test class TestPEAR\n";
+class Test2 extends PEAR {
+ function _Test2() {
+ print "This is the Test2 destructor\n";
+ $this->_PEAR();
+ }
+}
+
+class Test3 extends Test2 {
+}
+
+print "testing plain destructors\n";
$o = new TestPEAR("test1");
$p = new TestPEAR("test2");
-var_dump(get_class($o));
-var_dump(get_class($p));
+print "..\n";
+print "testing inherited destructors\n";
+$q = new Test3;
+
+print "..\n";
+print "script exiting...\n";
+print "..\n";
?>
--GET--
--POST--
--EXPECT--
-test class TestPEAR
+testing plain destructors
PEAR constructor called, class=testpear
PEAR constructor called, class=testpear
-string(8) "testpear"
-string(8) "testpear"
+..
+testing inherited destructors
+..
+script exiting...
+..
This is the TestPEAR(test1) destructor
PEAR destructor called, class=testpear
This is the TestPEAR(test2) destructor
PEAR destructor called, class=testpear
+This is the Test2 destructor