Object Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
empiresolutions
Forum Newbie
Posts: 20
Joined: Tue Apr 11, 2006 10:39 am
Location: Portland, Or

Object Error

Post by empiresolutions »

I have just recently updated my server to PHP 5.1. I am getting a grip of errors in my logs now related to an object i use. This is just one of the error.

Code: Select all

Undefined property:  object::$core in /var/www/vhosts/site.com/httpdocs/index.php
It is referencing a script i use like -

Code: Select all

// set object //
class object {};
$SITE = new object;

// difine //
$SITE->core = 'test string';

// in use //
echo"$SITE->core";
Has this type of object usage degraded in 5.1, or is there something i need to set in my now updated php.ini file.

Thanks.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Object Error

Post by Christopher »

empiresolutions wrote:I am getting a grip of errors
Is that like a murder of crows or a pod of whales?

Are they Warnings or Errors?
(#10850)
empiresolutions
Forum Newbie
Posts: 20
Joined: Tue Apr 11, 2006 10:39 am
Location: Portland, Or

Post by empiresolutions »

[Thu May 11 10:42:13 2006] [error] [client **.***.**.***] PHP Notice: Undefined property: object::$core in /var/www/vhosts/site.com/httpdocs/index.php on line 23, referer: http://www.site.com/

I have hidden the IP and changed site name to site.com
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

That is just a Notice. They are informational only. If you don't want Notices in your log then turn them off in php.ini.
(#10850)
empiresolutions
Forum Newbie
Posts: 20
Joined: Tue Apr 11, 2006 10:39 am
Location: Portland, Or

Post by empiresolutions »

perfect answer. what do i change in php.ini file?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Change your error_reporting directive. You can also change the error_reporting directive at runtime. You might also want to have a look at display_errors used in conjunction with ini_set().
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

empiresolutions wrote:perfect answer. what do i change in php.ini file?
Everah gave good links. If you just open up your php.ini file and page down a little there is normally a big section that describes error reporting and has a number of pre-defined settings that you just need to uncomment (and comment the current setting).
(#10850)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

The above posts are correct. *But* (yeah there's always a but :P) you should really adjust the code to remove the notices. Notices appear for a reason. Imagine you suddenly need to move this code to a shared server for a while where you have no control over the values defined in php.ini ? You'd be knackered. Fixing notices like the one above is usally just a case of small amounts of logic like this:

Code: Select all

if (isset($object->core)) //do this

//or using a ternary statement is sometimes appropriate

$foo = isset($object->core) ? $object->core : NULL;
/*
 Above reads:
 
 if (isset($object->core))
 { //then
    $foo = $object->core;
 }
 else
 {
     $foo = NULL;
 }
 */
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

d11wtq wrote:Notices appear for a reason.
You are right, this is exactly what notices are for -- to let you know what is going on for things like upgrades.
(#10850)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Even though notices are not critical error type things, you still want to fix them. They identify areas in your code in which there is something wrong. I myself am a stickler for writing clean, usable, error-free code as often as possible (which in my opinion is always). Something like the error you are getting would get me moving to fix it right away.

PS The links to the error reporting directives I gave you were for testing. You really do not want them turned on in production apps or in a production environment.
Post Reply