#38286 [Opn->Fbk]: Class with interface implemented by a parent class fails due to constants
| From: | jani@php.net | Date: | Sun, 19 Aug 2007 20:13:28 +0000 |
| Subject: | #38286 [Opn->Fbk]: Class with interface implemented by a parent class fails due to constants | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-116325@lists.php.net to get a copy of this message | ||
ID: 38286
Updated by: jani@php.net
Reported By: baldurien at bbnwn dot eu
-Status: Open
+Status: Feedback
Bug Type: Scripting Engine problem
Operating System: Windows XP
PHP Version: 5CVS-2006-08-01 (snap)
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows (zip):
http://snaps.php.net/win32/php5.2-win32-latest.zip
For Windows (installer):
http://snaps.php.net/win32/php5.2-win32-installer-latest.msi
Previous Comments:
------------------------------------------------------------------------
[2006-08-08 09:13:34] baldurien at bbnwn dot eu
Here is a zip file with less file (in fact, just 4) :
http://www.bbnwn.eu/works/stream-bugs-with-less-files.zip
Simply run php -f bug.php
------------------------------------------------------------------------
[2006-08-02 12:00:58] baldurien at bbnwn dot eu
Note : that BarInputStream.php and FooInputStream.php.
------------------------------------------------------------------------
[2006-08-02 12:00:17] baldurien at bbnwn dot eu
For the content of archive, you should look for Stream/bug.php.
For the number of files, no:
1. I tell you that a problem with require_once, hence, having all class
and interface declared in the same file work as expected
2. I can go down to 4 files. Whose content is that (I'm not at home,
today and tomorrow, so I can't send an archive file) :
--- bug.php
<?php
abstract class Loader {
protected abstract function loadFiles();
protected abstract function doSomething();
public final function load() {
$this->loadFiles();
$this->doSomething();
}
}
class BarLoader extends Loader {
protected function loadFiles() {require_once 'BarInputStream.php';}
protected function doSomething() {
$bar = new BarInputStream();
$bar->seek(1);
}
}
class FooLoader extends Loader {
protected function loadFiles() {require_once 'FooInputStream.php';}
protected function doSomething() {
$foo = new FooInputStream();
}
}
$b = new BarLoader();
$b->load();
$f = new FooLoader();
$f->load();
?>
--- InputStream.php
<?php
interface Stream {
const SEEK_SET = SEEK_SET;
const SEEK_CUR = SEEK_CUR;
const SEEK_END = SEEK_END;
public function seek($pos, $whence = Stream::SEEK_SET);
}
interface InputStream extends Stream {
public function read(&$data);
}
?>
--- BarInputStream
<?php
require_once 'InputStream.php';
abstract class BarStream implements Stream {
public function seek($pos, $whence = Stream::SEEK_SET) {
echo __CLASS__, '->', __FUNCTION__, '()', "\n";
}
}
class BarInputStream extends BarStream implements InputStream {
public function read(&$data) {
echo __CLASS__, '->', __FUNCTION__, '()', "\n";
}
}
?>
--- FooInputStream
<?php
require_once 'InputStream.php';
abstract class FooStream implements Stream {
public function seek($pos, $whence = Stream::SEEK_SET) {
echo __CLASS__, '->', __FUNCTION__, '()', "\n";
}
}
class FooInputStream extends FooStream implements InputStream {
public function read(&$data) {
echo __CLASS__, '->', __FUNCTION__, '()', "\n";
}
}
?>
---END
I will add a short notice (if that serve): this will not happen if you
don't call $bar->seek(1).
------------------------------------------------------------------------
[2006-08-02 10:16:52] tony2001@php.net
Please provide SHORT but COMPLETE reproduce script.
I don't think you need a bunch of files to get such a simple error
message. I'm pretty sure it's possible to reproduce it with just a
couple of classes in 10 lines.
# unzip stream-bugs.zip
Archive: stream-bugs.zip
creating: Stream/
inflating: Stream/BarInputStream.php
inflating: Stream/BarLoader.php
inflating: Stream/BarStream.php
inflating: Stream/bug.php
inflating: Stream/FooInputStream.php
inflating: Stream/FooLoader.php
inflating: Stream/FooStream.php
inflating: Stream/InputStream.php
inflating: Stream/Loader.php
inflating: Stream/Stream.php
I don't see any "bug.php" or anything else that could help first of all
to understand what is the problem.
------------------------------------------------------------------------
[2006-08-02 06:05:54] baldurien at bbnwn dot eu
If you read carefully, then you'll find a link :
http://www.bbnwn.eu/works/stream-bugs.zip
This an archive file containing all the sources (eg: the test case for
the bug), which when you call the file "bug.php" will show you an
example of bug.
I can't provide it on the server, as a PHP file, as it is a php4 server
(which does not support interface).
If you want a txt file with all the code inlined, then no : the bug is
DUE to the presence of require_once. The sole thing I can do is to
prepend the name of each file before, meaning you will have the create
each file on your own, while they are in the archive file.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/38286
--
Edit this bug report at http://bugs.php.net/?id=38286&edit=1