Object from a included page
Moderator: General Moderators
Object from a included page
hi to all, after a long time.
One thing really making me tense.
Can't we use object from the included page.
I have added common class and created object of used class in one page. And included this page in another page and try to use the object
from the included page.
Sometimes it's ok and works but sometimes throws an error like:
>>>Call to a member function {function name} on a non-object
And cannot used that object.
So what will be the solution for this?
Thanks in advance
One thing really making me tense.
Can't we use object from the included page.
I have added common class and created object of used class in one page. And included this page in another page and try to use the object
from the included page.
Sometimes it's ok and works but sometimes throws an error like:
>>>Call to a member function {function name} on a non-object
And cannot used that object.
So what will be the solution for this?
Thanks in advance
Re: Object from a included page
Can u show source code?
Re: Object from a included page
I have not declared the object as global
fileName:objectCreated.php
fileName:objectCalled.php
fileName:objectCreated.php
Code: Select all
require('class/Decease.php');
$objDecease = new Decease();
print 'created'.$objDecease;
Code: Select all
require "objectCreated.php";
print 'called'.$objDecease;
Re: Object from a included page
Two variants are possible:
1. Variable this object rewrite
2. Variable this object not set or empty
1. Variable this object rewrite
2. Variable this object not set or empty
Re: Object from a included page
And the object from the objectCalled.php cannot call the function of Decease Class.
I just created the example of what i said
Thanks
I just created the example of what i said
Thanks
Re: Object from a included page
Debug objectCalled.php. Insert this code before use {function}:
This error arises in this situation:
Consequently, variable $objDecease not object. Your task find place where $objDecease lose value (object type).
Code: Select all
var_dump($objDecease);
Code: Select all
$a = "I'm not object";
$a->func();
// Result: Fatal error: Call to a member function func() on a non-object
Re: Object from a included page
Thanks for the quick reply ziq,
Yeah i am trying to find out the place where this object lose it's object type.
But if i declared that object as global, it works perfectly. I think it is not necessary to declare as global to access the object.
Thanks
Yeah i am trying to find out the place where this object lose it's object type.
But if i declared that object as global, it works perfectly. I think it is not necessary to declare as global to access the object.
Thanks
Re: Object from a included page
Are you use $objDecease inside function?
Re: Object from a included page
Thanks ziq for the prompt responce
Ok wait , i will tell you my structure in more details.
I have a file, let's say a.php, which includes the page named Init.php which is inside the local hierarchy.
And this Init file also include the another file Init.php which is placed outside and common for all.
I have imported class file and created object of these class in this Inti.php file.
And i have not used object inside the function and try to use the object property from the file a.php
Ok wait , i will tell you my structure in more details.
I have a file, let's say a.php, which includes the page named Init.php which is inside the local hierarchy.
And this Init file also include the another file Init.php which is placed outside and common for all.
I have imported class file and created object of these class in this Inti.php file.
And i have not used object inside the function and try to use the object property from the file a.php
Re: Object from a included page
Sorry ziq, i got the error, you are right.
Init.php file is imported through the function,
Is there any way to access this object without declaring it as global
Thanks
Init.php file is imported through the function,
Is there any way to access this object without declaring it as global
Thanks
Re: Object from a included page
I have already started to think that it is magic 
Re: Object from a included page
NoIs there any way to access this object without declaring it as global
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Object from a included page
I is best to pass the object into the function that uses it. Or the the constructor of an class that uses it.pcoder wrote:Is there any way to access this object without declaring it as global
(#10850)