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??
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.
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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With