Re: Is this a php bug?



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';

.



Relevant Pages

  • Re: [PHP] Hidden include_path Fall Back?
    ... imacat@atlas /tmp/phpinc % cat inc/inc01.php ... have a lot of scripts that "accidently" works because of this, ... do not know whether I should fix it or not. ...
    (php.general)
  • Hidden include_path Fall Back?
    ... imacat@atlas /tmp/phpinc % cat inc/inc01.php ... have a lot of scripts that "accidently" works because of this, ... do not know whether I should fix it or not. ...
    (php.general)
  • RE: [PHP] Whats wrong the __autoload()?
    ... [PHP] What's wrong the __autoload? ... RoR is still an academic toy. ... if they need a fat cat... ... "In March 2007 David Heinemeier Hansson filed three Rails related trademark ...
    (php.general)
  • Re: [PHP] Alternate Colors in Rows
    ... a bunch of different ways to skin this particular cat. ... For fun, I wanted to show you something I came up with early in my PHP ... I haven't had to do the alternating color thing too many times so never ...
    (php.general)
  • Re: true?2:false?3:4 - is it a bug?
    ... PHP appears to have different results here to several other major ... andyh@server:~/tmp/ternary$ cat ternary.pl ... The issue is operator associativity; Perl implements the ternary ... implemented it with the opposite associativity of the "original" languages. ...
    (comp.lang.php)