开发者

Some error in php function

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜