php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64800 Example 1 appears incorrect
Submitted: 2013-05-09 14:35 UTC Modified: 2013-10-23 04:37 UTC
From: bsasser at sindtech dot net Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: n/a
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bsasser at sindtech dot net
New email:
PHP Version: OS:

 

 [2013-05-09 14:35 UTC] bsasser at sindtech dot net
Description:
------------
The comments for Example 1 at http://www.php.net/manual/en/language.oop5.interfaces.php appear to be technically incorrect.

The comment states:
"// Fatal error: Class BadTemplate contains 1 abstract methods
// and must therefore be declared abstract (iTemplate::getHtml)"

When I copy & paste the entire example into a text editor and 'Search' for the word 'abstract', the only two places it appears are in the comment as noted above.

This also means iTemplate::getHtml is not declared 'abstract'.

Declaration of Template::getHtml:
    public function getHtml($template)

The only way it seems the comments can be correct are if declaring an interface automatically makes those functions or methods, abstract.  There is no such mention of this, that I could find, at the specified URL.


Test script:
---------------
URL: http://www.php.net/manual/en/language.oop5.interfaces.php

// This will not work
// Fatal error: Class BadTemplate contains 1 abstract methods
// and must therefore be declared abstract (iTemplate::getHtml)
class BadTemplate implements iTemplate
{
    private $vars = array();
  
    public function setVariable($name, $var)
    {
        $this->vars[$name] = $var;
    }
}
?>


Expected result:
----------------
// This will work
// No error: because there is no method or function explicitly declared 'abstract' in this example.
{
    private $vars = array();
  
    public function setVariable($name, $var)
    {
        $this->vars[$name] = $var;
    }
}
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-23 04:37 UTC] krakjoe@php.net
-Status: Open +Status: Not a bug
 [2013-10-23 04:37 UTC] krakjoe@php.net
The example in the documentation is correct.

The error "Fatal Error: Class %s contains %d abstract methods and must therefore be declared abstract" is raised because by declaring that you are implementing an interface and then only providing a partial implementation you are implicitly creating an abstract class, that cannot be instantiated because it is incomplete, but have not declared the abstract methods requested as you should in preparation for further inheritance completing the implementation of the interface.

I hope that gives you a good understanding of your mistake.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 15:01:32 2024 UTC