Page 1 of 1

Object Error

Posted: Thu May 11, 2006 1:59 pm
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.

Re: Object Error

Posted: Thu May 11, 2006 2:34 pm
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?

Posted: Thu May 11, 2006 2:48 pm
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

Posted: Thu May 11, 2006 3:07 pm
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.

Posted: Thu May 11, 2006 3:12 pm
by empiresolutions
perfect answer. what do i change in php.ini file?

Posted: Thu May 11, 2006 3:36 pm
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().

Posted: Thu May 11, 2006 3:40 pm
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).

Posted: Thu May 11, 2006 4:47 pm
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;
 }
 */

Posted: Thu May 11, 2006 5:48 pm
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.

Posted: Thu May 11, 2006 6:02 pm
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.