Tried a bit with your implementation and i wonder why you
allow redeclared functions to be abstract:

class pass {
function show() {
echo "Call to function show()\n";
}
}

class fail extends pass {
abstract function show();
}

Another thing i wonder is that you did not allow static abstract
while we allow mixing static and non static:

<?php
class a {
static function show() { echo "a\n"; }
}

class b extends a{
function show() { echo "b\n"; }
}

class c extends b {
static function show() { echo "c\n"; }
}

a::show();
$t = new b();$t->show();
c::show();
?>

The solution to the above is the following:
cvs -z3 -q diff zend_compile.c (in directory S:\php4-ZE2\Zend)
Index: zend_compile.c
===================================================================
RCS file: /repository/ZendEngine2/zend_compile.c,v
retrieving revision 1.324
diff -u -r1.324 zend_compile.c
--- zend_compile.c 20 Nov 2002 18:00:21 -0000 1.324
+++ zend_compile.c 21 Nov 2002 22:00:25 -0000
@@ -1529,6 +1529,19 @@
ce->__call = ce->parent->__call;
}

+static zend_bool do_inherit_method_check(zend_function *child, zend_function *parent) {
+ /* You cannot change from static to non static and vice versa
+ */
+ if (child->common.is_static != parent->common.is_static) {
+ if (child->common.is_static) {
+ zend_error(E_COMPILE_ERROR, "Cannot make non static function %s() static in class %s", child->common.function_name, child->common.scope ? child->common.scope->name : "");
+ } else {
+ zend_error(E_COMPILE_ERROR, "Cannot make static function %s() non static in class %s", child->common.function_name, child->common.scope ? child->common.scope->name : "");
+ }
+ }
+ return SUCCESS;
+}
+
void zend_do_inheritance(zend_class_entry *ce, zend_class_entry *parent_ce)
{
zend_function tmp_zend_function;
@@ -1540,7 +1553,7 @@
/* STATIC_MEMBERS_FIXME */
/* zend_hash_merge(ce->static_members, parent_ce->static_members, (void (*)(void *)) zval_add_ref, (void *) &tmp, sizeof(zval *), 0); */
zend_hash_merge(&ce->constants_table, &parent_ce->constants_table, (void (*)(void *)) zval_add_ref, (void *) &tmp, sizeof(zval *), 0);
- zend_hash_merge(&ce->function_table, &parent_ce->function_table, (void (*)(void *)) function_add_ref, &tmp_zend_function, sizeof(zend_function), 0);
+ zend_hash_merge_ex(&ce->function_table, &parent_ce->function_table, (void (*)(void *)) function_add_ref, sizeof(zend_function), (zend_bool (*)(void *, void *))do_inherit_method_check);
ce->parent = parent_ce;
if (!ce->handle_property_get)
ce->handle_property_get = parent_ce->handle_property_get;

And now it prints:
/usr/src/php4-HEAD/tests/classes/static_mix.php(6) : Fatal error - Cannot make static function show() non static in class b

marcus

At 19:00 20.11.2002, Andi Gutmans wrote:
andi            Wed Nov 20 13:00:24 2002 EDT

  Modified files:
    /ZendEngine2        zend_compile.c zend_compile.h zend_execute.c
                        zend_language_parser.y zend_language_scanner.l
  Log:
  - Fix build (thanks Marcus)
  - Implement abstract methods, syntax:
  -    abstract function foo($vars);
  - I don't see any reason why modifiers such as static/public need to be
  - used with abstract. PHP is weakly typed and there would be no meaning to
  - this anyway. People who want a strictly typed compiled language are
  - looking in the wrong place.


Index: ZendEngine2/zend_compile.c
diff -u ZendEngine2/zend_compile.c:1.323 ZendEngine2/zend_compile.c:1.324
--- ZendEngine2/zend_compile.c:1.323    Sun Nov 10 17:02:28 2002
+++ ZendEngine2/zend_compile.c  Wed Nov 20 13:00:21 2002
(...)

Reply via email to