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 6908865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:37:00+00:00 2026-05-27T08:37:00+00:00

I have strict error reporting. I have to use isset and it make me

  • 0

I have strict error reporting. I have to use isset and it make me to write long, repetitive chains of variables in PHP. I have sometimes to write code like this:

if (isset($my_object->an_array[$a_variable])):
        $other_variable = $my_object->an_array[$a_variable];
else:
        $other_variable = false;
endif;

or

if (isset($my_object->an_array[$a_variable])):
        return $my_object->an_array[$a_variable];
endif;

Sometimes it is longer and more complicated. It isn’t readable and take too much time to type. I’d like to get rid of it.

The question
Is there a way to write $my_object->an_array[$a_variable] only once?

  • 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-05-27T08:37:00+00:00Added an answer on May 27, 2026 at 8:37 am

    In the end I have found two solutions.

    I. There is operator @ in PHP. It is very dangerous, tough.
    http://www.php.net/manual/en/language.operators.errorcontrol.php

    However, it is acceptable in my situation.

    1. This is not a fatal error.
    2. The value of undefined variable is defined as null. I’m fine with testing for this or using implicit conversions.
    3. I can use $php_errormsg in extreme situations.

    The code example:

    $tmp = $false_object->property->property; #Throw notice
    $tmp = $false_array['a_field']['a_field']; #Throw notice
    $tmp = @$false_object->property->property; #Quiet
    $tmp = @$false_array['a_field']['a_field']; #Quiet
    echo $php_errormsg; #I can print that notice
    

    The downside is I don’t receive information about lack of quotes in brackets.

    $a = array('e'=>false);
    $tmp = $a[e]; #Throw notice
    $tmp = @$a[e]; #Quiet
    echo $php_errormsg; #This variable still works
    

    II. It is possible to use operator &.

    1. The value of undefined variable will be NULL too.
    2. The $php_errormsg variable doesn’t work for undefined variables.
    3. I get notice for lack of quotes in brackets, though.

    The code example:

    $tmp = $false_object->property->property; #Throw notice
    $tmp = $false_array['a_field']['a_field']; #Throw notice
    $tmp = &$false_object->property->property; #Quiet
    $tmp = &$false_array['a_field']['a_field']; #Quiet
    var_dump($tmp); #NULL;
    

    The lack of quotes problem:

    $array = array('a_field'=>true);
    $tmp = $array[a_field]; #Throw notice
    $tmp = @$array[a_field]; #Quiet
    $tmp = &$array[a_field]; #Throw notice
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could you please have a look at my code below. #!C:\Perl\bin\perl.exe use strict; use
I have a mod_perl script: use strict; use warnings FATAL => 'all'; use 5.010001;
i have something like: #!/usr/bin/perl use strict; use warnings; use CGI::Simple; use DBI; my
I'm working with PHP and have got the error logging turned on and turned
I am using ZendAMF for remoting. <?php error_reporting(E_ALL | E_STRICT); //error reporting, not needed
I have the following script: use 5.12.4; use strict; use warnings; say Enter a
We have created the following simple Mojolicious controller: package SampleApp::Pages; # $Id$ use strict;
We have the following problem while running the git fsck --full --strict command: error:
When using use strict perl will generate a runtime error on unsafe constructs. Now
I have email sending code which doesn't work without any error messages (by doesn't

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.