Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP using Declare ? What is a tick?

Tags:

php

declare

I am a little bit confused by the PHP function declare.

What exactly is a single tick? I thought a tick equals one line of code?

But if I use:

function myfunc() {         print "Tick";    }  register_tick_function("myfunc");  declare(ticks=1) {    echo 'foo!bar'; } 

The script prints:

"Tick" 2 Times??

like image 981
opHASnoNAME Avatar asked Mar 14 '10 07:03

opHASnoNAME


People also ask

What are ticks in PHP?

Put simply, a tick is a special event that occurs internally in PHP each time it has executed a certain number of statements. These statements are internal to PHP and loosely correspond to the statements in your script.

What is tick function?

The tick function is unlike other lifecycle functions in that you can call it any time, not just when the component first initialises. It returns a promise that resolves as soon as any pending state changes have been applied to the DOM (or immediately, if there are no pending state changes).

What is PHP declare?

The declare keyword sets an execution directive for a block of code. If the declare statement is not followed by a block then the directive applies to the rest of the code in the file.


1 Answers

You get a tick for each line ; and each block {} Try that:

declare(ticks=1) echo 'foo!bar'; 

No block, no extra tick.

declare(ticks=1) {{ echo 'foo!bar'; }} 

More extraneous blocks = more ticks.

PS: by the way, ticks are quite the exotic feature and they're only useful in a few extremely rare situations. They are not equivalent to threading or anything. If, for you, ticks are the solution to a problem then you should post about your problem in another question because it's probably not the right solution to it.

like image 175
Josh Davis Avatar answered Sep 27 '22 22:09

Josh Davis