|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-08-01 18:43 UTC] baldurien at bbnwn dot eu
Description: ------------ Hi, I've got this following error : Fatal error: Cannot inherit previously-inherited constant SEEK_SET from interface InputStream in bugs\Stream\FooInputStream.php on line 5 The contract is simple : it tell me that I'm redefining a constant, in class FooInputStream, while I use the same code in BarInputStream (see source below) The Idea of what I'm trying to do is nothing less than simple OOP, by having an abstract class implementing class of an interface A for me, extending the abstract class, and implementing another interface that also implements (or extends) A. Reproduce code: --------------- See http://www.bbnwn.eu/works/stream-bugs.zip run bugs.php for a complete test The test will do the following : 1. get all file finishing by Loader.php, which are class supposed to load some kind of class, extending class Loader. 2. get all class, and via Reflection, check if we may instanciate them, store them into a classes array (this will also bug if you directly call $clazz->newInstance()->load()) 3. create a new instance, and call load() method. It was tested on php5.1.4 but also on php5.2, and php6 (snapshots dated on 1 august) It is somehow related to bug 33732 (http://bugs.php.net/bug.php?id=33732) Note that if you don't use a loop, and instead put require_once 'BarLoader.php'; require_once 'FooLoader.php'; It fails. But: if BarStream and FooStream does not implements Stream, it works. It also fails without using reflection : $b = new BarLoader(); $b->load(); $f = new FooLoader(); $f->load(); Expected result: ---------------- No fatal error for FooInputStream, like in class BarInputStream Actual result: -------------- A fatal error, in class FooInputStream PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 27 02:00:02 2025 UTC |
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).