Jump to content

Include problem


wepnop
 Share

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

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

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