Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8477633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:31:17+00:00 2026-06-10T18:31:17+00:00

I spent more than 10 hours to find out the typo for debugging my

  • 0

I spent more than 10 hours to find out the typo for debugging my PHP program. I expected PHP would produce an error when using an undefined variable. But when it is used as an object in a method, it doesn’t. Is there a reason for it?

<?php

    $oClass = new MyClass;
    // $oCless->tihs('key', 'taht');    //<-- triggers the error: Notice: Undefined variable
    $oClass->tihs('key', 'taht');
    echo $oClass->arr['key'];

    class MyClass {
        public $arr = array('key' => 'foo');

        function tihs($key, $value) {
            $tihs->arr[$key] = $value;  //<-- this does not cause an error message.
        }
    }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:31:19+00:00Added an answer on June 10, 2026 at 6:31 pm

    Normally if the error reporting level is set to E_ALL | E_STRICT (or E_ALL as of PHP 5.4.0) it should spit out an E_STRICT error. For instance, this code:

    error_reporting(E_ALL | E_STRICT);
    $tihs->adrr = 453;  
    

    Produces:

    Strict Standards: Creating default object from empty value in [...]
    

    Interestingly enough, if you specifically create an array instead of an ordinary variable as a property of an object that doesn’t exist, e.g.:

    error_reporting(E_ALL | E_STRICT);
    $tihs->adrr[25] = 453;  
    

    No strict standards error is shown! It looks like this could potentially be something PHP folks might want to fix, because I’m not aware this is documented nor I think there’s a legitimate reason for this behaviour.

    For the record, in both cases regardless of the error a new stdClass is being created on the fly instead, like sberry mentions in his answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've spent more than 20 hours on Stackoverlfow to find a solution to my
Update: I have spent more than 2 hours to google, but I can't find
I've spent more than a few hours humbling myself on the ACM ICPC's problem
can anybody help with the above SourceSafe error? I've spent hours trying to find
Spent many hours and still can't figure that out. sampleData.json file contains the following
I've spent a few hours trying to figure out how to install a plugin
I have spent hours trying to find an answer to this, and have come
I spent the morning figuring out the basics ANTLR to find out it's LL,
Spent a solid hour trying to sort out why on earth this (coffeescript) $.ajax
Spent a good few hours on this now and don't seem to be getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.