How to avoid reusing ticks in every file in PHP 7

Overview

In PHP 5.6, it seems that adding declare(ticks=1)and then using register_tick_function()will follow any inclusions and provide relevant profiling information.

In PHP 7+, however now it seems to me that I should add declare(ticks=1)to each file. I use this to profile each method call when the page loads, and now I don’t want to add this to every PHP file on my system (some of them cannot be if they are in libraries).

I can not find anything in the docs about the changes that were made for this.

Replication steps

Create the following 2 files:

index.php

<?php

declare(ticks=1);
$count = 0;

register_tick_function('ticker');
function ticker() {
  global $count;
  $count++;
}

$foo = 'foo';
$bar = 'bar';

include dirname(__FILE__) . '/inc.php';

echo $count;

inc.php

<?php

#declare(ticks=1);

$baz = "baz";
$qux = "qux";

results

Running php index.phpin the terminal gives me:

  • PHP 5.6 - 7
  • PHP 7.0 - 5

declare(ticks=1) inc.php :

  • PHP 5.6 - 8
  • PHP 7.0 - 8

- , PHP 7 +?

+2
1

PHP, https://bugs.php.net/bug.php?id=71448

- declare (ticks = 1) PHP 7.0. , declare(), per-file per-scope.

, , - , PHP 5.6, ​​ PHP 7.0. , , , , , .

, , PHP 7 +

PHP7

+2

All Articles