Jump to content

The "magic" of the exception class


brendan6

Recommended Posts

When i create a new instance of the exception class, it somehow knows the page uri and and the line number on which the exception was created.

 

$e = new Exception("Oops");
echo $e;

Outputs: exception 'Exception' with message 'Oops' in C:\wamp\www\test.php:3 Stack trace: #0 {main}

 

How does it know the page which the instance of itself resides on?

Link to comment
Share on other sites

Because PHP is magical.

 

If you would like to perform some magic yourself, check out the following special variables: __FILE__, __LINE__

http://us2.php.net/manual/en/language.constants.predefined.php

 

For more fun, check out debug_backtrace() too!

http://us2.php.net/manual/en/function.debug-backtrace.php

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.