Skip to content

Commit 4e2c87e

Browse files
committed
Fixed bug #67741 (auto_prepend_file messes up __LINE__)
This also fixes bug #54081
1 parent 169ac35 commit 4e2c87e

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

main/main.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2579,8 +2579,21 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC)
25792579
#endif
25802580
zend_set_timeout(INI_INT("max_execution_time"), 0);
25812581
}
2582-
retval = (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 3, prepend_file_p, primary_file, append_file_p) == SUCCESS);
25832582

2583+
{
2584+
/*
2585+
If cli primary file has shabang line and there is a prepend file,
2586+
the `start_lineno` will be used by prepend file but not primary file,
2587+
save it and restore after prepend file been executed.
2588+
*/
2589+
int orig_start_lineno = CG(start_lineno);
2590+
2591+
CG(start_lineno) = 0;
2592+
retval = (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 1, prepend_file_p) == SUCCESS);
2593+
CG(start_lineno) = orig_start_lineno;
2594+
2595+
retval = retval && (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 2, primary_file, append_file_p) == SUCCESS);
2596+
}
25842597
} zend_end_try();
25852598

25862599
#if HAVE_BROKEN_GETCWD

sapi/cli/tests/bug67741.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Bug #67741 (auto_prepend_file messes up __LINE__)
3+
--INI--
4+
include_path={PWD}
5+
auto_prepend_file=bug67741_stub.inc
6+
--SKIPIF--
7+
<?php
8+
include "skipif.inc";
9+
?>
10+
--FILE--
11+
#!/bin/env php
12+
<?php
13+
echo "primary lineno: ", __LINE__, "\n";
14+
?>
15+
--EXPECT--
16+
prepend lineno: 2
17+
primary lineno: 3

sapi/cli/tests/bug67741_stub.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
echo "prepend lineno: ", __LINE__, "\n";
3+
?>

0 commit comments

Comments
 (0)