Jump to content

Help understanding include_once function


nloding

Recommended Posts

The topic title doesn't quite illustrate what I mean.  Here's my setup:

 

<?php

//File: includes/page.inc
function getPage($page = null) {
if($page == null) $page = "home";
include_once("$page.php");
}
//End page.inc

//File: index.php
include_once('includes/page.inc');
$db = new DBClass();

getPage();
//End index.php

//File: test.php
include_once('includes/page.inc');
$db = new DBClass();

include_once('home.php');
//End test.php

 

With index.php, the home.php page that is included using the function does NOT have access the $db variable declared right above it.  But if I skip the function call, and just include home.php, home.php DOES have access to $db.

 

If both are calling include_once, why the difference in scope?

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.