php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20924 Functions inside declare(ticks=1) cannot be used prior to definition
Submitted: 2002-12-10 13:38 UTC Modified: 2002-12-24 11:57 UTC
From: a_villacis at palosanto dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.0RC2 OS: Linux 2.4.7-10
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: a_villacis at palosanto dot com
New email:
PHP Version: OS:

 

 [2002-12-10 13:38 UTC] a_villacis at palosanto dot com
My configuration (as reported by phpinfo()):
./configure --with-apxs=/opt/httpd/bin/apxs 
 --with-mysql=/usr --with-gd 
 --with-curl=/opt/curl-7.10.1/ 
 --with-pdflib=/opt/pdflib/ 
 --with-zlib --enable-inline-optimizations 
 --enable-pcntl --enable-dio --with-ncurses 
 --enable-sockets
What I did (filename 'ticks_bug_php'):
--------------- CUT HERE --------------------
#!/usr/local/bin/php
<?php

	function predefined_out()
	{
		echo "Inside predefined_out()\n";
	}

	predefined_out();
	postdefined_out();

	function postdefined_out()
	{
		echo "Inside postdefined_out()\n";
	}

	declare(ticks = 1)
	{
		function predefined_in()
		{
			echo "Inside predefined_in()\n";
		}

		predefined_in();
		postdefined_in();

		function postdefined_in()
		{
			echo "Inside postdefined_in()\n";
		}
	}
?>
--------------- CUT HERE --------------------
What I expected:
 [avillaci@srv64 practica]$ ./ticks_bug_php 
 Inside predefined_out()
 Inside postdefined_out()
 Inside predefined_in()
 Inside postdefined_in()
 [avillaci@srv64 practica]$

What I got instead:

 [avillaci@srv64 practica]$ ./ticks_bug_php 
 Inside predefined_out()
 Inside postdefined_out()
 Inside predefined_in()

 Fatal error: Call to undefined function:  postdefined_in()     
 in /home/avillaci/programa/practica/ticks_bug_php on line
 25
 [avillaci@srv64 practica]$

PHP refuses to call postdefined_in() before its definition
inside the scope of 'declare(ticks=1){}', but has no problem
calling postdefined_out() before its definition, outside
the scope of 'declare(ticks=1){}'.
Any hints in solving this issue will be greatly appreciated.
Alex Villacis Lasso
a_villacis@palosanto.com


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-12 11:46 UTC] a_villacis at palosanto dot com
I just upgraded to version 4.3.0RC3 with the same
configure command, but the script gives the same message
as in the original posting.

This behavior is rather annoying, but a workaround is to 
declare the troublesome procedure *outside* the scope of
the 'declare(ticks=1) {}' block. However, this does not
seem to help if the new syntax 'declare(ticks=1);' is used
to cover the entire script under the declare() scope.

Alex Villacis Lasso
a_villacis@palosanto.com
 [2002-12-24 11:44 UTC] a_villacis at palosanto dot com
Same problem with 4.3.0RC4.
 [2002-12-24 11:57 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is actually not a bug. Because the declare() stuff works as some kind of conditional compile the functions will not be defined during parsing/compile, but only when the code is executed for the first time. Of course when the postdefined_in(); is reached the code below has not been executed before and thus you can an undefined function error. The same would happen if you'd put it in an if like this:

<?php

if (TRUE) {
    function blah1() {
    }

    blah1();
    blah2();

    function blah2() {
    }
}
?>


 [2004-03-07 17:28 UTC] 2072 at 2072productions dot com
Well this is maybe not a bug but it is a real problem when you use the pcntl extension to handle signals where you have to put a declare(ticks=1); for the whole script...

I think something has to be done with pcntl signal handling to fix that because it's really annoying.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 09:01:31 2025 UTC