Re: Is this a php bug?



On Jun 29, 11:04 am, SST <gcar...@xxxxxxx> wrote:
Hey friend, i don't agree with you.
We may always treat include/require as they include something into the
original file.
So if test1.php:
<?php
$a = 1;
?>
test2.php is:
<?php
include 'test1.php';
print $a;
?>
We may treat test2.php as:
<?php
$a = 1;
print $a;
?>

So let's look at test1/test2/test3. If we treat test3 as:
[yarco@localhost test]$ cat test3.php
<?php

class B implements C
{

}

interface C
{

}

class A extends B
{

}

?>[yarco@localhost test]$ php test3.php
[yarco@localhost test]$

It certainly could work fine. So i don't think it should give an error
when i do that.
And __autoload also does't give me any help.

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>

You can disagree all you want but that isn't how it works. Try this
one:

bar.php:
<?php
function bar() {
echo 'This is bar.';
}
?>

foo.php:
<?php
bar();
include('bar.php');
?>

And it throws an error because it doesn't know what bar() is. Just
because it's /logically/ the same as dropping the code in there
doesn't mean that's how it's actually evaluated.

.



Relevant Pages

  • Re: Classes vs functions
    ... Interfaces were Java's "solution" to multiple inheritance. ... in a way that one class may implement one or more interface. ... PHP; nobody would be obligated to use or abuse it. ... > resource-consuming) to be able to include an entire package. ...
    (comp.lang.php)
  • Re: Object Oriented Content System - the idea
    ... Would probably be difficult to enforce this militant style in PHP. ... (It's java, but you probably don't have to know java to see what's going ... The advantage of keeping them private or protected has been to prevent using ... way of private inner class and interface) In PHP this typically means another ...
    (comp.lang.php)
  • Re: PHP Scripts in an ASP Page
    ... what you do not realize is that two script language systems aren't ... ASP has the ability to use configurable script language engines like ... interface to abstract language specifics from the web execution context ... limitation in PHP. ...
    (microsoft.public.inetserver.iis)
  • Re: One class per file
    ... I think it is a good idea to put each single class (or interface) in a separate file. ... OS and PHP handle that many with acceptable performance so I need not worry about it? ... echo 'A'; ... None of these tests mean anything, especially on a shared server. ...
    (comp.lang.php)
  • Re: php 5 classes: public, protected and private
    ... Private members can be accessed by members of the class only. ... I'm trying to make a bit of sense of the php 5 ... the great Tony Marston is back to trolling again. ... the interface is the way to interact with the ...
    (comp.lang.php)