Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
426 views
in Technique[技术] by (71.8m points)

PHP using Declare ? What is a tick?

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??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...