php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #30741 Interfaces must appear before use
Submitted: 2004-11-10 01:43 UTC Modified: 2004-11-10 23:24 UTC
From: chris at experiencetours dot com dot au Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.0.2 OS: Linux
Private report: No CVE-ID: None
 [2004-11-10 01:43 UTC] chris at experiencetours dot com dot au
Description:
------------
I am not sure if this is a bug or a documentation issue, but if an instance of a class is created before the Interface definition, the class will be undefined.  Although this is not directly covered in the manual, it is inconsistent with functions, which can be reference before they are defined.

./configure --with-apache=/usr/local/src/apache/apache_1.3.31 --with-libxml-dir=/usr/local/libxml2 --enable-calendar --with-openssl=/usr --wi
th-pear --with-zlib --enable-ftp --with-bz2 --with-ldap --with-pdflib --without-mysql --with-pgsql --with-pspell

Reproduce code:
---------------
$concreteType = new ConcreteType();
echo $concreteType->getText();
$c2 = new ContreteType2();
echo $c2->getText();

interface IType
{
  public function getText();
}
abstract class AbstractType implements IType
{
}
class ConcreteType extends AbstractType
{
  public function getText()
  {
    return "Hello World!!!";
  }
}
class ConcreteType2 implements IType
{
  public function getText()
  {
    return "Hello World!!!";
  }
}

Expected result:
----------------
"Hello World!!!""Hello World!!!"

Actual result:
--------------
Fatal error: Class 'ConcreteType' not found in /usr/local/apache/htdocs/bookallot/test.php on line 1


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-10 08:11 UTC] derick@php.net
This is expected behavior, but should be mentioned in PHP 5's migration guide (http://de.php.net/manual/en/migration5.oop.php)
 [2004-11-10 09:42 UTC] vrana@php.net
It is written at http://www.php.net/manual/en/migration5.incompatible.php :

"In some cases classes must be declared before used. It only happens only if some of the new features of PHP 5 are used. Otherwise the behaviour is the old."

Thus I think this bug can be marked as bogus.

 [2004-11-10 22:34 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

We decided on this behavior....
 [2004-11-10 23:24 UTC] chris at experiencetours dot com dot au
Thank you for the quick response and pointers.  I have now read the migration guide and it does appear there.  You may want to mention it in the manual since this is what I used as a reference, but I guess it is common sense to have to define the class and interfaces before referenceing them.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 03:01:29 2024 UTC