Bug #64800 [Opn->Nab]: Example 1 appears incorrect

From: Date: Wed, 23 Oct 2013 04:37:10 +0000
Subject: Bug #64800 [Opn->Nab]: Example 1 appears incorrect
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-10526@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64800&edit=1 ID: 64800 Updated by: krakjoe@php.net Reported by: bsasser at sindtech dot net Summary: Example 1 appears incorrect -Status: Open +Status: Not a bug Type: Bug Package: Documentation problem Operating System: n/a PHP Version: Irrelevant Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2013-05-09 14:35:13] 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; } } ?> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64800&edit=1

« previous php.doc.bugs (#10526) next »