Page 1 of 1

Require_once works but functions aren't reachable

Posted: Thu Mar 25, 2010 10:59 am
by vwduud
I am updating from PHP 4.XXXX to PHP 5.3.2 for a web application. This application "works" properly in PHP 4.XXXX. For this post, the "require_once" directives "work" properly: they find the external file and make the functions with the file visible to "other" php modules.

Now, fast foward to PHP 5.3.2. Although the "require_once" calls do not fail (as long as the file is present - which it is), the functions with the "required_once" file are not visible to be used. I get "call to undefined function".

Example:

func.php

Code: Select all

<?
   function do_something() {
      echo "function from an external file";
   }
?>
main_module.php:

Code: Select all

<?
   require_once("func.php");
   
   do_something();
?>
Running main_module.php will yield "call to undefined function do_something() in main_module.php"

Any help?

Re: Require_once works but functions aren't reachable

Posted: Thu Mar 25, 2010 1:28 pm
by requinix
Have you tried with that exact code?

Re: Require_once works but functions aren't reachable

Posted: Thu Mar 25, 2010 1:48 pm
by vwduud
tasairis wrote:Have you tried with that exact code?
Here's the exact code:

logon.php:

Code: Select all

<?php
 
require_once("config.inc.php");
include("junk_pile.php");
 
do_me();
?>
config.inc.php:

Code: Select all

<?
$backup_path = 'c:/backups/';
 
// MySQL DB config info
$sql_conf = array();
$sql_conf[ "host" ]          = "localhost";
$sql_conf[ "user" ]          = "smarts";
$sql_conf[ "pass" ]          = "smarts";
$sql_conf[ "db" ]            = "AMGB-6";
 
$sess_conf = array();
$sess_conf[ "table" ]        = "sessions";  //table to store session data
$sess_conf[ "openatstart" ]  = true;        //open connection at session open?
 
 
$bgcolor1 = "#7cc691";
$bgcolor2 = "#ccE0cc";
 
$date_format = "%a, %b %e";
$time_format = "%l:%i %p";
?>
junk_pile.php:

Code: Select all

<?
   function do_me() {
      echo "junk pile php";
   }
?>
Same results as the "cleaned-up" named code modules above, with config.inc.php added in

Re: Require_once works but functions aren't reachable

Posted: Thu Mar 25, 2010 3:19 pm
by AbraCadaver
Need <?php not <?

Re: Require_once works but functions aren't reachable

Posted: Thu Mar 25, 2010 3:40 pm
by requinix
AbraCadaver wrote:Need <?php not <?
For the record: I figured that the new PHP might not have short tags enabled but I wanted to be sure.

Re: Require_once works but functions aren't reachable

Posted: Thu Mar 25, 2010 3:44 pm
by AbraCadaver
tasairis wrote:
AbraCadaver wrote:Need <?php not <?
For the record: I figured that the new PHP might not have short tags enabled but I wanted to be sure.
I figured that's where you were going with it as the original code wouldn't have given an error at all :-)