SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Possible to find last executed function or last parsed line?

    I have this module which I intend to use for pdfparsing, and it dies one me without a word. Looking at the code it's littered with die(''), meaning there is a lot of places it may die, but without a word why.

    So I was wondering if there is a way to include the last function called or the line number at which current execution is made?

    Thinking I could then do a stringreplace of the die('')'s to a more meaningful errormsg.

    Other approaches/ideas on this is also appriciated!

  2. #2
    SitePoint Enthusiast toytron's Avatar
    Join Date
    Nov 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for reply, but it didnt really tell wether it's possible to find the last executed function or at which position the php-parser is currently at.

  4. #4
    SitePoint Enthusiast toytron's Avatar
    Join Date
    Nov 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No indeed. It's a way to handle errors. With try / catch you can send the messages you want and that makes it a lot easier to find errors like the ones you have.

  5. #5
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Salathe
    Software Developer and PHP Manual Author.

  6. #6
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I ended up using function trigger-error , doing replace die(''); with {trigger_error("I'm dying.. ", E_USER_ERROR); die('dead');} Which gave me the line it was triggered on.

    Thanks for input!

  7. #7
    SitePoint Evangelist dmsuperman's Avatar
    Join Date
    Feb 2005
    Location
    A box
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another possibility is to do this:
    Code:
    die("It died in file: " . __FILE__ . " on line " . __LINE__);
    But triggering errors is a lot more helpful.
    <(^.^<) \(^.^\) (^.^) (/^.^)/ (>^.^)>
    Core 2 Duo E8400 clocked @ 3.375GHz, 2x2GB 800MHz DDR2 RAM
    5x SATA drives totalling 2.5TB, 7900GS KO, 6600GT

  8. #8
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dmsuperman View Post
    Another possibility is to do this:
    Code:
    die("It died in file: " . __FILE__ . " on line " . __LINE__);
    Ah thanks, that was exact what I was looking for in the first place

  9. #9
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    You should not use die...it is not a form of error handling because it kills the whole script. Not what you want in the real programming world.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  10. #10
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    You should not use die...it is not a form of error handling because it kills the whole script. Not what you want in the real programming world.
    True enough, but as with this situation, it's not my code, and it was the easiest way of spotting the error. I found the massive use of die('') strange myself.


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
  •