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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:11:46+00:00 2026-05-23T01:11:46+00:00

Alrighty, I’m getting quite frustrated, namely because I thought I had this issue solved,

  • 0

Alrighty, I’m getting quite frustrated, namely because I thought I had this issue solved, or had accomplished this successfully before.

Quick preliminary:

  • PHP 5.3.6.
  • Error reporting cranked to 11. (-1 actually; future safe, all errors/notices)

I have a class, it aggregates request parameters. For giggles here is a stripped down version:

class My_Request{
    private $_data = array();
    public function __construct(Array $params, Array $session){
        $this->_data['params']  = $params;
        $this->_data['session'] = $session;
    }
    public function &__get($key){
        // arrg!
    }
}

Anyways, the reason for arrg! is, no matter what I try, I always get an error whenever the $key doesn’t exist. I’ve tried:

// doesn't work
$null = null;
if(isset($this->_data[$key])){ return $this->_data[$key]; }
return $null;

// doesn't work
return $this->_data[$key];

I’ve been told ternary operators cannot result in a reference, ergo, that of course doesn’t work, but we know that from the if condition attempt anyways. What happens, for example:

// params will have foo => bar, and session hello => world
$myRequest = new My_Request(array('foo' => 'bar'), array('hello' => 'world'));

// throws an error - Undefined index: baz
echo $myRequest->params['baz'];

I’m losing my mind here; perhaps I hallucinated a scenario where I achieved this. Is it not possible to (without throwing a notice) successfully do this?


Clarification: Things I’ve tried

The aforementioned:

// no check, no anything, just try returning : fails
public function &__get($key){
    return $this->_data[$key];
}

// null variable to pass back by reference : fails
public function &__get($key){
    $null = null;
    if(isset($this->_data[$key])){
        return $this->_data[$key];
    }
    return $null;
}

Other attempts:

// can't work - can't return null by reference nor via ternary : fails
public function &__get($key){
    return isset($this->_data[$key])
        ? $this->_data[$key]
        : null;
}
  • 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-23T01:11:46+00:00Added an answer on May 23, 2026 at 1:11 am
     echo $myRequest->params['baz'];
    

    The isset check in your __get function will look up "params" from $this->_data and return the array. The notice you get is from outside the class and about a key "baz" in the returned array – which in your example was never actually defined.

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

Sidebar

Related Questions

Alright, I'm not sure if this question has been asked before so if it
Alrighty, coding in Perl and just had a quick question. I have class created
Alrighty so below I have this script doing exactly what I want; I'm using
Alrighty well straight to it, I'm using this guide as I learn SDL and
Alrighty, let's try this again! I'm currently developing an application that will be relying
Alrighty, I don't know how I did this, probably the AS3 gods became angry
Alrighty so, I've been wanting to learn C for awhile, and now I have
Alright, this one's interesting. I have a solution, but I don't like it. The
Alright, I hope this isn't too broad a question but my curiosity got the
Alright, I'm having a hard time explaining this, let me know if I should

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.