SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    __FILE__ behaviour in conjunction with eval

    PHP Code:
    $line "return ' - Error in file: ' . __FILE__ ;";
    define('_LOGLINE_'$line);
    echo eval(
    _LOGLINE_); 
    Used this way the output of __FILE__ looks like :
    - Error in file: /home/datune/config/config.inc.php(93) : eval()'d code
    But if you just do
    PHP Code:
    echo '- Error in file:' __FILE__
    The output looks like :
    - Error in file: /home/datune/config/config.inc.php
    Anybody knows why this happens? (besides the obvious one that it is run through eval)

  2. #2
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Navin
    /home/datune/config/config.inc.php(93) : eval()'d code

    Filename(Line) : Notice

    Nothing wrong with that.
    Did you even bother to read my post?

  3. #3
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    __FILE__ is populated at compile time and means "current compilation unit" in zend engine. Since evaled string is a new unit, engine chooses a new name for it and it is not equal to the containing file's name. The new name consists of calling filename, line number and comment. The same applies to dynamically created functions:

    PHP Code:
    $f create_function('''echo __FILE__;');
    $f(); 

  4. #4
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now that's something I did not know! Thanks stereofrog


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •