Jump to content

Include problem


wepnop

Recommended Posts

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...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.