# Exception thrown without a stack frame

- Thread: https://externals.io/message/30349
- Original archive: https://news-web.php.net/php.internals/30349
- Started by Jakob Buchgraber on 2007-06-28T20:25:55+00:00
- Messages: 10
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #30349 — Jakob Buchgraber — 2007-06-28T20:25:55+00:00

URL: https://externals.io/message/30349#30349

Hey!

I sometimes get the following error
> > […]

What does this mean? Should this ever happen or does it somehow say that
there is a bug in PHP. I am asking this because I've had this error a
few times and it's pretty hard to debug.

Thanks!

- Jakob

---

## #30352 — Richard Lynch — 2007-06-28T21:02:28+00:00

URL: https://externals.io/message/30349#30352 · In reply to: #30349

I would guess that an exception is getting thrown before you PHP
script has actually started...

Something in the parsing of GET/POST data or file upload handler,
perhaps.

Can you nail down what was being done when it occurred, perhaps by
sending the error to Apache error log, and then looking at previous
line[s] to see what scripts are getting accessed.


> Hey!
>
> I sometimes get the following error
> > […]
>
> What does this mean? Should this ever happen or does it somehow say
> that
> there is a bug in PHP. I am asking this because I've had this error a
> few times and it's pretty hard to debug.
>
> Thanks!
>
> - Jakob
>
> --
> 
> 
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

---

## #30353 — Andrew Minerd — 2007-06-28T22:01:43+00:00

URL: https://externals.io/message/30349#30353 · In reply to: #30349

> I sometimes get the following error
> > […]
> 
> What does this mean?

When we see these, they're typically from our custom session handler.

-- 
Andrew Minerd
Software Architect
The Selling Source, Inc.


On Thu, 28 Jun 2007 22:25:55 +0200
jakob.buchgraber@gmail.com (Jakob Buchgraber) wrote:

> Hey!
> 
> I sometimes get the following error
> > […]
> 
> What does this mean? Should this ever happen or does it somehow say that
> there is a bug in PHP. I am asking this because I've had this error a
> few times and it's pretty hard to debug.
> 
> Thanks!
> 
> - Jakob

---

## #30373 — Adam Ashley — 2007-06-30T01:31:18+00:00

URL: https://externals.io/message/30349#30373 · In reply to: #30353

> > […]
>
> When we see these, they're typically from our custom session handler.
>

In my experience that error is almost certainly in a piece of your  
code that is run after the main execution of the program is complete.  
So places to check are shutdown functions (things registered with  
 `register_shutdown_function()`), custom session handlers and object  
destructors. Basically any piece of code that can be called after the  
official execution of your script is complete and clean-up is occuring.

Adam Ashley

---

## #30375 — Jakob Buchgraber — 2007-06-30T14:15:16+00:00

URL: https://externals.io/message/30349#30375 · In reply to: #30373

Adam Ashley wrote:
> > […]
> 
> In my experience that error is almost certainly in a piece of your code 
> that is run after the main execution of the program is complete. So 
> places to check are shutdown functions (things registered with 
> `register_shutdown_function()`), custom session handlers and object 
> destructors. Basically any piece of code that can be called after the 
> official execution of your script is complete and clean-up is occuring.
> 
> Adam Ashley

Yes that's right. This error occured in my Logger class as all the 
messages are written into a buffer and when the destructor is called the 
data in the buffer are written into a file.
Is that a bad solution? Any alternatives?

Thank you!

Jay

---

## #30376 — Jakob Buchgraber — 2007-06-30T14:19:06+00:00

URL: https://externals.io/message/30349#30376 · In reply to: #30373

Adam Ashley wrote:
> > […]
> 
> In my experience that error is almost certainly in a piece of your code 
> that is run after the main execution of the program is complete. So 
> places to check are shutdown functions (things registered with 
> `register_shutdown_function()`), custom session handlers and object 
> destructors. Basically any piece of code that can be called after the 
> official execution of your script is complete and clean-up is occuring.
> 
> Adam Ashley

Yes that's right! I am having a Logger class where all log messages are 
written into a buffer and when the destructor is called the data are 
transformed into some format (e.g. json) and then stored in a file and I 
got an exception writing data into the file as I missed the rights.

Is that a bad solution? Any suggestions?

Thank you!

Jakob Buchgraber

---

## #30377 — Jakob Buchgraber — 2007-06-30T14:37:43+00:00

URL: https://externals.io/message/30349#30377 · In reply to: #30352

Richard Lynch wrote:
> I would guess that an exception is getting thrown before you PHP
> script has actually started...
> 
> Something in the parsing of GET/POST data or file upload handler,
> perhaps.
> 

Definitely not. I was just testing my Logging class in Zend Studio. So 
no input GET/POST data were passed to the script and it's also not a 
problem with ZE as I can reproduce it with PHP 5.2.3 on the command line 
as well.

> Can you nail down what was being done when it occurred, perhaps by
> sending the error to Apache error log, and then looking at previous
> line[s] to see what scripts are getting accessed.
> 
> 
> > […]
> 
> 
I am sorry. I can't reproduce the example with a small script. I am 
trying hard but I always get a normal error message with a stack trace. 
If I can reproduce it, I'll send it to the list.

- Jakob

---

## #30378 — Jakob Buchgraber — 2007-06-30T14:55:50+00:00

URL: https://externals.io/message/30349#30378 · In reply to: #30352

Okay, I can now reproduce the problem. Here is the code:
<?php
class Foo {
     public function __destruct() {
         throw new Exception();
     }
}

$a = new Foo();
?>

I couldn't reproduce it before as I didn't assign the instance of Foo to 
a variable, however Christian Hoffmann pointed me out that I need to do 
this in order to get the desired error.

- Jakob

---

## #30379 — Ralph Schindler — 2007-06-30T15:18:40+00:00

URL: https://externals.io/message/30349#30379 · In reply to: #30378

I've run into this before.. essentially, you can't do that ;)

http://us2.php.net/language.oop5.decon (second note)

Nor, can you throw exceptions anytime after the engine starts shutting down.

-ralph

Jakob Buchgraber wrote:
> Okay, I can now reproduce the problem. Here is the code:
> <?php
> class Foo {
>     public function __destruct() {
>         throw new Exception();
>     }
> }
> 
> $a = new Foo();
> ?>
> 
> I couldn't reproduce it before as I didn't assign the instance of Foo to 
> a variable, however Christian Hoffmann pointed me out that I need to do 
> this in order to get the desired error.
> 
> - Jakob

---

## #30476 — Richard Lynch — 2007-07-06T03:55:56+00:00

URL: https://externals.io/message/30349#30476 · In reply to: #30378

> Okay, I can now reproduce the problem. Here is the code:
> <?php
> class Foo {
>      public function __destruct() {
>          throw new Exception();
>      }
> }
>
> $a = new Foo();
> ?>
>
> I couldn't reproduce it before as I didn't assign the instance of Foo
> to
> a variable, however Christian Hoffmann pointed me out that I need to
> do
> this in order to get the desired error.

The only solution I know of is:

Don't do that.

:-)

Or, accept the fact that your code running in the destructor is
happening outside the realm of time and space as far as PHP is
concerned.

Bascially, anything that goes wrong before PHP starts interpreting
your script (i.e., custom file upload, custom session, custom php.ini
settings extension) and anything that happens after PHP has finished
the last line of your code (session_close function, desctrutors, etc)
is going to have a not-so-informative message about which PHP file /
line caused the problem, or a lack of a stack or whatever, because PHP
is not in a stable state of existence at that point.

Deal with it, or don't do what you're doing are the only real options...

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
