views:

58

answers:

1

This Is my code http://www.ideone.com/R1P4b

I'm use simple_html_dom class

In end of file if i rung one line is no error and if i rung two line is return one error

echo getImg($text1) . "<br/>";
echo getImg($text2) . "<br/>";
error

but

echo getImg($text1) . "<br/>";
or
echo getImg($text2) . "<br/>";

Don't error

Please help me fix it

+5  A: 

Declare the functions isbnFromText(), isbn2Image() and imagePix() outside of getImg().

I don't know exactly how PHP handles functions that are declared inside another function, but apparently, it puts them into the same scope and if you run the outer function twice, they are declared again.

Example:

function a() {
    function b() {
        print 'foo';
    }
    b();
}

a();
a();

prints

foo
Fatal error: Cannot redeclare b() (previously declared in /t.php:4) on line 3

Update:

Learn more about functions, especially example 3. It is also stated there:

All functions and classes in PHP have the global scope - they can be called outside a function even if they were defined inside and vice versa.

PHP does not support function overloading, nor is it possible to undefine or redefine previously-declared functions.

Felix Kling
This error same in my code, Can you help me fix it ?
Thoman
@Thoman: What do you mean? Have you read the first sentence of my answer? Have you done it and still get the error?
Felix Kling
@Felix Kling Great Thanks
Thoman
Sorry because i don't see it :))
Thoman
@Thoman: No worries, can happen ;)
Felix Kling