ZE2 constructors

[email protected] ((Marcus Börger))
Newsgroups php.dev
Message-ID <[email protected]>
Hi Zeev,

according to the plans the following test file should PASS:

################
--TEST--
The new constructor/destructor is called
--SKIPIF--
<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip 
ZendEngine 2 needed'); ?>
--FILE--
<?php

class early {
         function early() {
                 echo "early::early\n";
         }
         function __construct() {
                 echo "early::__construct\n";
         }
         function __destruct() {
                 echo "early::__destruct\n";
         }
}

class late {
         function __construct() {
                 echo "late::__construct\n";
         }
         function late() {
                 echo "late::late\n";
         }
         function __destruct() {
                 echo "late::__destruct\n";
         }
}

$t = new early();
$t->early();
unset($t);
$t = new late();
$t->late();
//unset($t); delay to end of script

echo "Done\n";
?>
--EXPECTF--
early::__construct
early::early
early::__destruct
late::__construct
late::late
Done
late::__destruct
#########################

However it fails and this patch is needed which also fixees the last final 
problem
mentioned already:

#########################
Index: Zend/zend_compile.c
===================================================================
RCS file: /repository/ZendEngine2/zend_compile.c,v
retrieving revision 1.375
diff -u -r1.375 zend_compile.c
--- Zend/zend_compile.c 25 Feb 2003 10:03:26 -0000      1.375
+++ Zend/zend_compile.c 28 Feb 2003 19:14:52 -0000
@@ -916,6 +916,9 @@
                 && ((current_access_type->u.constant.value.lval & 
ZEND_ACC_PPP_MASK) != (new_modifier->u.constant.value.lval & 
ZEND_ACC_PPP_MASK))) {
                 zend_error(E_COMPILE_ERROR, "Multiple access type 
modifiers are not allowed");
         }
+       if (((current_access_type->u.constant.value.lval | 
new_modifier->u.constant.value.lval) & (ZEND_ACC_ABSTRACT | 
ZEND_ACC_FINAL)) == (ZEND_ACC_ABSTRACT | ZEND_ACC_FINAL)) {
+               zend_error(E_COMPILE_ERROR, "Cannot use the final modifier 
on an abstract class member");
+       }
         if (((current_access_type->u.constant.value.lval | 
new_modifier->u.constant.value.lval) & (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL)) 
== (ZEND_ACC_PRIVATE | ZEND_ACC_FINAL)) {
                 zend_error(E_COMPILE_ERROR, "Cannot use the final modifier 
on a private class member");
         }
@@ -974,7 +977,7 @@
                         fn_flags |= ZEND_ACC_PUBLIC;
                 }

-               if ((short_class_name_length == name_len) && 
(!memcmp(short_class_name, name, name_len))) {
+               if ((short_class_name_length == name_len) && 
(!memcmp(short_class_name, name, name_len)) && 
!CG(active_class_entry)->constructor) {
                         CG(active_class_entry)->constructor = 
(zend_function *) CG(active_op_array);
                 } else if ((function_name->u.constant.value.str.len == 
sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1) && 
(!memcmp(function_name->u.constant.value.str.val, 
ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)))) {
                         CG(active_class_entry)->constructor = 
(zend_function *) CG(active_op_array);
#########################

regards
marcus



-- 
----------------------------------------------------------------------
Marcus Börger - Looking for all sorts of freelance work - just ask...

Did i help you? Consider a gift:
http://www.amazon.de/exec/obidos/wishlist/ho722v0rg1u0
----------------------------------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.