leijae Posted July 5, 2011 Share Posted July 5, 2011 Happy 4th! I've done a lot of looking around searched the forums, and google... can't find a solution. Error: Fatal error: Call to undefined function getDirectory() in C:\xampp\htdocs\project\session_var.php on line 22 <?php if (isset($_SESSION['user'])) { getDirectory('webs/sum2011'); function getDirectory( $path = '.', $level = 0 ) { $ignore = array( '.', '..' ); $dh = @opendir( $path ); $i = -2; while( false !== ( $file = readdir( $dh ) ) && ( $i < 5) ) { $i++; if( !in_array( $file, $ignore ) ) { if(is_dir( "$path/$file" ) ) { echo "<a href='$path/$file/index.php'>$file $i</a><br />"; getDirectory( "$path/$file", ($level+1) ); } } } closedir( $dh ); } } else { getDirectoryFul('webs/sum2011'); function getDirectoryFul( $path = '.', $level = 0 ) { $ignore = array( '.', '..' ); $dh = @opendir( $path ); while( false !== ( $file = readdir( $dh ) ) ) { if( !in_array( $file, $ignore ) ) { if(is_dir( "$path/$file" ) ) { echo "<a href='$path/$file/index.php'>$file $i</a><br />"; getDirectoryFul( "$path/$file", ($level+1) ); } } } closedir( $dh ); } } ?> Link to comment https://forums.phpfreaks.com/topic/241103-undefined-function-error-but-it-is/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 5, 2011 Share Posted July 5, 2011 Because your function definition is inside of a conditional statement, the definition must come before the call to the function. Link to comment https://forums.phpfreaks.com/topic/241103-undefined-function-error-but-it-is/#findComment-1238390 Share on other sites More sharing options...
leijae Posted July 5, 2011 Author Share Posted July 5, 2011 Thanks that worked, but I didn't read any resources that made that distinction. Link to comment https://forums.phpfreaks.com/topic/241103-undefined-function-error-but-it-is/#findComment-1238395 Share on other sites More sharing options...
PFMaBiSmAd Posted July 5, 2011 Share Posted July 5, 2011 Functions need not be defined before they are referenced, except when a function is conditionally defined as shown in the two examples below. When a function is defined in a conditional manner such as the two examples shown. Its definition must be processed prior to being called. Link to comment https://forums.phpfreaks.com/topic/241103-undefined-function-error-but-it-is/#findComment-1238397 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.