php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43323 Wrong count abstract methods
Submitted: 2007-11-18 13:42 UTC Modified: 2008-01-29 11:14 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: felipensp at gmail dot com Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3 OS:
Private report: No CVE-ID: None
 [2007-11-18 13:42 UTC] felipensp at gmail dot com
Description:
------------
Wrong count abstract methods when name of method is same class name.

When used the same code with namespace, the count is correct.

Reproduce code:
---------------
<?php

// namespace foo; # The count is correct

abstract class bar {
    abstract public function bar();
}

class foo extends bar {
}


Expected result:
----------------
Fatal error: Class foo contains 1 abstract methods and must therefore be declared abstract or implement the remaining methods (bar::bar)

Actual result:
--------------
Fatal error: Class foo contains 2 abstract methods and must therefore be declared abstract or implement the remaining methods (bar::bar, bar::bar)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-18 10:44 UTC] felipe@php.net
It also occur in PHP 5.3.

(Ugly?) patch:

Index: Zend/zend_execute_API.c
===================================================================
RCS file: /repository/ZendEngine2/zend_execute_API.c,v
retrieving revision 1.331.2.20.2.24.2.19
diff -u -u -r1.331.2.20.2.24.2.19 zend_execute_API.c
--- Zend/zend_execute_API.c     15 Jan 2008 11:47:05 -0000      1.331.2.20.2.24.2.19
+++ Zend/zend_execute_API.c     18 Jan 2008 10:32:51 -0000
@@ -1649,15 +1649,21 @@
 typedef struct _zend_abstract_info {
        zend_function *afn[MAX_ABSTRACT_INFO_CNT + 1];
        int cnt;
+       int ctor;
 } zend_abstract_info;
 
 static int zend_verify_abstract_class_function(zend_function *fn, zend_abstract_info *ai TSRMLS_DC) /* {{{ */
 {
        if (fn->common.fn_flags & ZEND_ACC_ABSTRACT) {
-               if (ai->cnt < MAX_ABSTRACT_INFO_CNT) {
+               if (ai->cnt < MAX_ABSTRACT_INFO_CNT && ((fn->common.fn_flags & ZEND_ACC_CTOR) == 0 || ai->ctor < 1)) {
                        ai->afn[ai->cnt] = fn;
                }
-               ai->cnt++;
+               if (!ai->ctor || !(fn->common.fn_flags & ZEND_ACC_CTOR)) {
+                       ai->cnt++;
+               }
+               if (!ai->ctor && fn->common.fn_flags & ZEND_ACC_CTOR) {
+                       ai->ctor = 1;
+               }
        }
        return 0;
 }

 [2008-01-29 11:14 UTC] dmitry@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 06:01:30 2024 UTC