Jump to content

[SOLVED] Strict Standards Error.


NixNod

Recommended Posts

Hey guys, I got one Strict Standards message in my application.

I think, better than explain is show what is happening.

 

I Got the following Class (Registry class)

<?php
class Registry {

    private $vars = array();

    public function __set($varName, $varValue)
    {
        if (!isset($this->vars[$varName])) {
            $this->vars[$varName] = $varValue;
        }
    }

    public function __get($varName)
    {
        if (isset($this->vars[$varName])) {
            return $this->vars[$varName];
        }
    }

    public function __unset($varName)
    {
        if (isset($this->vars[$varName])) {
            unset($this->vars[$varName]);
        }
    }

    public function __isset($varName) {
        return isset($this->vars[$varName]);
    }
}
?>

 

In some file (ex: index.php) I got the following piece of code:

<?php
...
$registry = new Registry;
$registry->Mysql = new Mysql; // <<< LINE 27
...
?>

 

 

But I got the following message:

Strict Standards: Creating default object from empty value in index.php on line 27

 

 

I know that I can change the error reporting thing, but I like my App running very well.

 

 

Found it on PHP Bugs:

http://bugs.php.net/bug.php?id=42852&edit=1

 

My PHP version is 5.2.3 running on Windows

 

 

Someone knows what is happening?

 

Thanks at all.

Link to comment
Share on other sites

Hmm. I run 5.2.4 on my Windows machine, and when I copypaste the exact code you are using (plus add simple "class Mysql { }", I do not get any errors. Perhaps the error is somewhere else, despite what PHP is claiming or there is some weird bug (Are you sure your autoloader is working?)

 

Here's the code I used, which did not produce any errors for me:

<?php

error_reporting(E_ALL | E_STRICT);

class Registry {

    private $vars = array();

    public function __set($varName, $varValue)
    {
        if (!isset($this->vars[$varName])) {
            $this->vars[$varName] = $varValue;
        }
    }

    public function __get($varName)
    {
        if (isset($this->vars[$varName])) {
            return $this->vars[$varName];
        }
    }

    public function __unset($varName)
    {
        if (isset($this->vars[$varName])) {
            unset($this->vars[$varName]);
        }
    }

    public function __isset($varName) {
        return isset($this->vars[$varName]);
    }
}

class Mysql { }

$registry = new Registry;
$registry->Mysql = new Mysql; 

?>

Link to comment
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.