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
https://forums.phpfreaks.com/topic/93035-the-magic-of-the-exception-class/
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

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.