wepnop Posted May 3, 2011 Share Posted May 3, 2011 Im having a scope problem when creating a library. This is the test file: <?php include_once 'lib/lib_inventario.php'; session_start(); hacerFormulario('Memoria Ram'); ?> And this the library importer: <?php $lib_usada = 'Inventario'; include_once 'registroglobal.php'; $reg = RegistroGlobal::GetInstance(); include 'errores.php'; include_once 'test.php'; include 'sesiones.php'; include 'bd.php'; include 'seguridad.php'; include 'usuarios.php'; include 'web_inventario.php'; $reg->setConf('Libreria usada', 'Basica'); ?> Well, i explain what the second code does. It imports a few modules that have function or object definitions in they. So the idea is that just importing the lib_whatever file you import all the functions you need, and also set some configuration settings. My problem with the first code is that it says that the function is undefined, when it sure exist in web_inventario file... Quote Link to comment https://forums.phpfreaks.com/topic/235414-include-problem/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 3, 2011 Share Posted May 3, 2011 Have you checked for spelling errors in the function name? Does any of the other code in the web_inventario.php file work? Quote Link to comment https://forums.phpfreaks.com/topic/235414-include-problem/#findComment-1209830 Share on other sites More sharing options...
requinix Posted May 3, 2011 Share Posted May 3, 2011 Tip: if you need functions or classes defined in a file, use require_once(). If PHP somehow can't include the file it will raise an error and stop executing. Is web_inventario.php in the lib directory? When you include a file PHP will look according to the current working directory. In most situations, the CWD is the directory with the file that was first executed - not the directory with the file that's currently executing. If /a.php includes /b/b.php, then that file includes "c.php", PHP will look for /c.php and not /b/c.php. The two easiest ways to make sure you include the right file are require_once $_SERVER["DOCUMENT_ROOT"] . "/lib/web_inventario.php"; // for including files relative to the root of your website // or /* PHP 5.3+ */ require_once __DIR__ . "/web_inventario.php"; /* PHP // for including files relative to this file running right now Quote Link to comment https://forums.phpfreaks.com/topic/235414-include-problem/#findComment-1209942 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.