Jump to content

Recommended Posts

hi guys, i've had this problem for a while now

anyhow i've this is my code

 

user.php

class user

{

var name = "";

function user($n)

{

$this->name = $n;

}

 

function getName()

{

return $this->name;

}

 

util.php

include('user.php');

 

 

page1.php

include('util.php');

$user = new user("ivanh");

 

page2.php

include('util.php');

print $user->getName();

 

in page2.php i get this error:

Fatal error: Call to a member function getName() on a non-object in page2

 

please let me know if you need anything else required to help me

 

thanks, Ivan

Link to comment
https://forums.phpfreaks.com/topic/180195-global-objects/
Share on other sites

This might be a good time for some web server 101 -

 

Web servers are stateless. They don't know or care what happened before or what will happen next. When any http/https request has been serviced, all resources used on the page that was requested are destroyed. The only information that ties any page request to any other page request is what the browser supplies when it makes the http/https request to the server.

 

You would need to create an instance of your class in a session variable if you wanted it to persist between any separate http/https page requests.

Link to comment
https://forums.phpfreaks.com/topic/180195-global-objects/#findComment-950927
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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