# How do I know if the code is in eval?

- Thread: https://externals.io/message/75918
- Original archive: https://news-web.php.net/php.internals/75918
- Started by Aaron Lewis on 2014-07-23T02:23:29+00:00
- Messages: 3
- 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

---

## #75918 — Aaron Lewis — 2014-07-23T02:23:29+00:00

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

Hi,

How can I know the line no in eval()'d code?

e.g eval()'d code on line 1 (I couldn't find the definition of that
output, so I had to ask it here)

zend_get_executed_lineno(TSRMLS_C) doesn't seem to be the right value

Also, I'm not sure how to tell if the code is in eval() either

-- 
Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print:   9F67 391B B770 8FF6 99DC  D92D 87F6 2602 1371 4D33

---

## #75945 — Derick Rethans — 2014-07-23T09:50:38+00:00

URL: https://externals.io/message/75918#75945 · In reply to: #75918

> Hi,
> 
> How can I know the line no in eval()'d code?
> 
> e.g eval()'d code on line 1 (I couldn't find the definition of that
> output, so I had to ask it here)
> 
> zend_get_executed_lineno(TSRMLS_C) doesn't seem to be the right value

AFAIK, it's all one string, so on one line. At least that's what the 
engine "thinks".

> Also, I'm not sure how to tell if the code is in eval() either

zend_get_executed_filename has "eval()'d code" in the output:
https://github.com/derickr/xdebug/blob/master/xdebug_handler_dbgp.c#L378

cheers,
Derick

-- 
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
Posted with an email client that doesn't mangle email: alpine

---

## #75967 — Sara Golemon — 2014-07-23T16:38:52+00:00

URL: https://externals.io/message/75918#75967 · In reply to: #75918

>
> How can I know the line no in eval()'d code?
>
Are you asking how to determine where the eval'd code was called from?
 There's a way, but it's a bit messy:

Walk up EG(current_execute_data) until you get to the opline pointing
at ZEND_EVAL (this will probably be the current stack, or one above,
depending on where your error got thrown from).  opline->lineno will
have the line number where eval was called from.

You can take a look at the implementation for `debug_backtrace()` for
inspiration if need be.  Just bear in mind that eval() is an op, not a
function.

> Also, I'm not sure how to tell if the code is in eval() either
>
As Derick mentioned, the "executed file" is a good hint.  Though if
you're walking up the execute data already, you'll probabaly notice
the ZEND_EVAL instruction along the way.

-Sara
