Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
You may say its not a critical bug? Well, its more crazy then critical.
The problem is in start_timer function.
Its your function:
function timer_start($name) {
global $timers;
list($usec, $sec) = explode(' ', microtime());
$timers[$name]['start'] = (float)$usec + (float)$sec;
$timers[$name]['count'] = isset($timers[$name]['count']) ? $timers[$name]['count']++ : 1;
}
Any timer's count field is always 1. Just don't know... Maybe its some php bug or else. Try it, you'll see.
P.S. My PHP 4.3.6.
But this works:
$timers[$name]['count'] = isset($timers[$name]['count']) ? ++$timers[$name]['count'] : 1;
Probably it'll work for U too.
Crazy, ha?
Comment | File | Size | Author |
---|---|---|---|
#3 | bootstrap.inc_8.patch | 653 bytes | puregin |
Comments
Comment #1
markus_petrux CreditAttribution: markus_petrux commentedIt is initialized to 1 the first time you call, say timer_start('mytimer'). The next time you call it, the counter is incremented.
Comment #2
puregin CreditAttribution: puregin commentedCan't reproduce. For example, the page timer seems to work fine. I'm marking this as normal priority.
I'm running PHP 5.0.4. Djun
Comment #3
puregin CreditAttribution: puregin commentedI spoke too soon. This bug does appear to exist. I tried
This indeed gives the wrong answer (1) for count, rather than the expected count (>= 2) unless the count is preincremented. Does this have to do with operator precedence? In any case, here's a patch...
Comment #4
puregin CreditAttribution: puregin commentedComment #5
markus_petrux CreditAttribution: markus_petrux commentedI spoke too soon too. A good catch indeed.
Wouldn't it be clear using
count+1
instead of++count
?Comment #6
puregin CreditAttribution: puregin commentedI think the pre-increment syntax is relatively clear...
Renaming the issue to be more descriptive
Comment #7
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedcommitted.
Comment #8
john.money CreditAttribution: john.money commentedWhy does the variable need to be checked if isset? Incrementing a variable will always make a null variable value 1. Just,
$timers[$name]['count']++;
Comment #9
Crell CreditAttribution: Crell commented@ Gestaltware: That only works if you don't mind generating an E_NOTICE. Numerous people are trying to push for E_ALL compliance for better future-proofing, which makes the isset() check necessary.
Comment #10
john.money CreditAttribution: john.money commentedAh, ok. Thanks Crell for point that out.
Comment #11
(not verified) CreditAttribution: commented