Jump to content


Problem with putting require_once() in a class function concerning objects...

  • Please log in to reply
No replies to this topic

#1 Balagi

  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 12 October 2006 - 07:47 PM

Here is a sample of the code I'm trying to fix.  I create an object $a and want to be able to use that same object on other pages that I load (require_once) through a function.

// index.php
class A {
  function load_page($page) {
    require_once($page . '.php');

$a = new A;

echo $a; // prints Object id #1 as it should

$a->load_page('test'); /* If I replace this line with require_once('test.php'); the A object will carry over, but that's not what I'm trying to do */


// test.php
echo "test text"; // prints "test text", I just added this to make sure the file was being loaded
echo $a; // prints nothing, this is what I'm trying to fix.. I want this to print Object id #1 like it did on index.php

I'm pretty new to class/object orriented programming, but basically I want my A object that was defined to index.php to carry on to other pages that I load with my $a->load(); function.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users