php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #78218 function intercepts execution of code that is not executed
Submitted: 2019-06-26 14:05 UTC Modified: 2019-06-26 16:09 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: lozinskiy dot artem at gmail dot com Assigned:
Status: Open Package: Unknown/Other Function
PHP Version: 7.2.19 OS: Ubuntu 18.04 LTS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: lozinskiy dot artem at gmail dot com
New email:
PHP Version: OS:

 

 [2019-06-26 14:05 UTC] lozinskiy dot artem at gmail dot com
Description:
------------
---
From manual page: https://php.net/function.register-tick-function
---
PHP Version 7.1.30-1+ubuntu18.04.1+deb.sury.org+
Linux ubuntu 4.15.0-20-generic #21-Ubuntu SMP Tue Apr 24 06:16:15 UTC 2018 x86_64
---

function intercepts execution of code that is not executed

Test script:
---------------
<?php
declare(ticks=1);

function my_function() {

    echo print_r(debug_backtrace(), 1) . '<br/>';
    
}

register_tick_function('my_function', true);

$t = false;
$ar = ['test1' => '111'];

var_dump('->' . __METHOD__ . ' on ' . __FILE__ . ':' . __LINE__);

foreach ($ar as $k => $e) {
    
    $t = ($k === 'test2');
    
    var_dump('$t==='. var_export($t, 1));
    
    if ($t===false) {
        continue;
    }
    
    var_dump('this line code is not executed (execute "continue")');
    
    test2();
    test3();    // this will handled or ..
    // test4(); // uncomment this and this will handled (but function not exist)
}

var_dump('->' . __METHOD__ . ' on ' . __FILE__ . ':' . __LINE__);

function test2() {
    // this never handled (why? =))
    return 1;
}

function test3() {
    var_dump('->' . __METHOD__ . ' on ' . __FILE__ . ':' . __LINE__);
}

Expected result:
----------------
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 10 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 12 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 13 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 
/var/www/test.local/public/test/tick.php:15:string '-> on /var/www/test.local/public/test/tick.php:15' (length=49)
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 15 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 19 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 
/var/www/test.local/public/test/tick.php:21:string '$t===false' (length=10)
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 21 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 
/var/www/test.local/public/test/tick.php:34:string '-> on /var/www/test.local/public/test/tick.php:34' (length=49)
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 34 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 39 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 43 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 

Actual result:
--------------
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 10 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 12 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 13 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 
/var/www/test.local/public/test/tick.php:15:string '-> on /var/www/test.local/public/test/tick.php:15' (length=49)
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 15 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 19 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 
/var/www/test.local/public/test/tick.php:21:string '$t===false' (length=10)
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 21 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 30 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 
/var/www/test.local/public/test/tick.php:34:string '-> on /var/www/test.local/public/test/tick.php:34' (length=49)
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 34 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 39 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 
Array ( [0] => Array ( [file] => /var/www/test.local/public/test/tick.php [line] => 43 [function] => my_function [args] => Array ( [0] => 1 ) ) ) 

---
that wrong...
---
on line 30 function intercepted execution on this line

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-06-26 14:14 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2019-06-26 14:14 UTC] requinix@php.net
Because the very first thing that happens when execution enters the function is that execution immediately leaves the function. And as documented, "not all statements are tickable".
 [2019-06-26 14:30 UTC] lozinskiy dot artem at gmail dot com
But why on line 30 this function executed?
After all, up to 30 lines the cycle must be completed and the code will not be executed further.
 [2019-06-26 14:48 UTC] requinix@php.net
Whatever the actual magical process is behind ticks, I don't think there's a bug here.

Look at https://3v4l.org/hneib/vld#output to see exactly what PHP is doing with the code.
 [2019-06-26 14:56 UTC] lozinskiy dot artem at gmail dot com
>> Whatever the actual magical process is behind ticks, I don't think there's a bug here.
Seriously, I made a convenient code analysis for myself using this function, but because of this there is no bug, as you said, I cannot trust this analysis, for me this is a bug and a problem, besides, only here is this behavior, and how can catch or identify this moment? How can I determine that the function has been correctly reversed here and not here?
 [2019-06-26 15:05 UTC] requinix@php.net
-Status: Not a bug +Status: Re-Opened
 [2019-06-26 15:28 UTC] lozinskiy dot artem at gmail dot com
for example see this code

<?php
declare(ticks=1);
function my_function() {
    echo print_r(debug_backtrace(), 1) . '<br/>';
}
register_tick_function('my_function', true);
$t = false;
$check = ['a'];
foreach ($check as $e) {
    $t = false;
    if ($t===false) {
        break; // break;
    } else {
        delete_db(); // =)
    }
}
function delete_db() {}
---

analysis show me that execute delete_db, and this is problem
I see that in the alpha version of php 7.4 there is no such problem, all of a sudden, it pleases, here now to get a patch for php 7.1
 [2019-06-26 15:45 UTC] cmb@php.net
-Status: Re-Opened +Status: Feedback -Assigned To: +Assigned To: cmb
 [2019-06-26 15:45 UTC] cmb@php.net
PHP 7.1 is no longer actively supported[1] (it receives only
security fixes).  Does this issue also happen with any actively
supported PHP version?

[1] <https://www.php.net/supported-versions.php>
 [2019-06-26 16:03 UTC] lozinskiy dot artem at gmail dot com
-Status: Feedback +Status: Assigned
 [2019-06-26 16:03 UTC] lozinskiy dot artem at gmail dot com
>> Does this issue also happen with any actively
supported PHP version?
Yes, on versions 7.2-7.3, this problem persists.
 [2019-06-26 16:09 UTC] cmb@php.net
-Status: Assigned +Status: Open -PHP Version: 7.1.30 +PHP Version: 7.2.19 -Assigned To: cmb +Assigned To:
 [2019-06-26 16:09 UTC] cmb@php.net
Thanks!
 [2024-05-03 11:11 UTC] brandon698sherrick at outlook dot com
That was so amazing. 

(https://github.com)(https://www-kynect.com)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 21:01:28 2024 UTC