Re: Is this a php bug?
- From: ZeldorBlat <zeldorblat@xxxxxxxxx>
- Date: Fri, 29 Jun 2007 15:27:07 -0000
On Jun 29, 11:21 am, Yarco <yarc...@xxxxxxxxx> wrote:
And when i use function declaration replace with interface and class,
it works fine. See below:
[yarco@localhost test]$ cat test1.php
<?php
function test1()
{
test2();
}
?>
[yarco@localhost test]$ cat test2.php
<?php
function test2()
{}
?>
[yarco@localhost test]$ cat test3.php
<?php
require_once dirname(__FILE__).'/test1.php';
require_once dirname(__FILE__).'/test2.php';
?>
[yarco@localhost test]$ php test3.php
[yarco@localhost test]$
If it works as you said, this can not happen.
On 6 29 , 10 28 , ZeldorBlat <zeldorb...@xxxxxxxxx> wrote:
On Jun 29, 9:49 am, Yarco <yarc...@xxxxxxxxx> wrote:
[yarco@localhost test]$ cat test1.php
<?php
interface C
{
}
class A extends B
{
}
?>[yarco@localhost test]$ cat test2.php
<?php
class B implements C
{
}
?>[yarco@localhost test]$ cat test3.php
<?php
require_once dirname(__FILE__).'/test2.php';
require_once dirname(__FILE__).'/test1.php';
?>[yarco@localhost test]$ php test3.php
PHP Fatal error: Interface 'C' not found in /home/yarco/Projects/test/
test2.php on line 3
[yarco@localhost test]$ php -v
PHP 5.2.1 (cli) (built: Jun 3 2007 12:45:11)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
Think about what's happening here. You include test2.php first. That
declares class B which implements interface C. But interface C is
defined in test1.php which hasn't been included yet, so the interface
is undefined.
Read about __autoload:
<http://www.php.net/autoload>
That works because the existence of test2() inside test1() isn't
checked at compile time -- it's checked a runtime. For instance, what
happens if you change test3.php to look like this:
require_once dirname(__FILE__).'/test1.php';
test1();
require_once dirname(__FILE__).'/test2.php';
.
- References:
- Is this a php bug?
- From: Yarco
- Re: Is this a php bug?
- From: ZeldorBlat
- Re: Is this a php bug?
- From: Yarco
- Is this a php bug?
- Prev by Date: Re: Is this a php bug?
- Next by Date: Re: Is this a php bug?
- Previous by thread: Re: Is this a php bug?
- Next by thread: Re: [PHP] PHP Brain Teasers [SPOILER]
- Index(es):
Relevant Pages
|