Hello, Rob!

> For what it is worth, the stack trace is not generated in the constructor (at 
> least from the perspective of the developer).

This is a design feature. In PHP, call frames for PHP functions are
stored in a separate stack. However, they are still stored following
the stack (LIFO) principle.

When a function returns a result, the memory of its frame will be
overwritten by the next one.
If the backtrace hasn’t been built while the stack still exists, there
might not be another chance.
That’s the main technical challenge.

For example, in Python (though this information might not be entirely
accurate), frames are objects that can be reused.

> Using reflection to create the exception without calling the constructor 
> still results in the stack trace being generated in the exception object.

That's because PHP objects actually have two constructors:

* The internal constructor

* The PHP-land constructor, called __construct

The internal constructor must always be called.

-- Ed

Reply via email to