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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:06:06+00:00 2026-05-14T06:06:06+00:00

If I have the following registry class: Class registry { private $_vars; public function

  • 0

If I have the following registry class:

Class registry 
{
    private $_vars;

    public function __construct()
    {
        $this->_vars = array();
    }

    public function __set($key, $val)
    {
        $this->_vars[$key] = $val;
    }

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

    public function printAll()
    {
        print "<pre>".print_r($this->_vars,true)."</pre>";
    }
}

$reg = new registry();

$reg->arr = array(1,2,3);
$reg->arr = array_merge($reg->arr,array(4));

$reg->printAll();

Would there be an easier way to push a new item onto the ‘arr’ array?
This code: ‘array[] = item’ doesn’t work with the magic set method, and I couldn’t find any useful info with google. Thanks for your time!

  • 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-14T06:06:07+00:00Added an answer on May 14, 2026 at 6:06 am

    If you have:

    $reg = new registry();
    $reg->arr = array(1,2,3);
    $reg->arr = 4;
    

    And you’re expecting:

    Array
    (
        [arr] => Array
            (
                [0] => 1
                [1] => 2
                [2] => 3
                [3] => 4
            )
    
    )
    

    All you need to do is update your __set method to:

    public function __set($key, $val){
      if(!array_key_exists($key, $this->_vars)){
        $this->_vars[$key] = array();
      }
      $this->_vars[$key] = array_merge($this->_vars[$key], (array)$val);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class class CItem { public: CItem(CRegistry &Registry) _Registry(Registry) {Registry.Register();} ~CItem()
I have Login.php form like this: class Form_Login extends Zend_Form { public function init()
I have a shared class which calls the following registry key which is used
I have created the following registry key (copied through regedit): HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test I would like
I have following model class in my application: public class Dispute { public long
I have the following code: RegistryKey installKey = Registry.LocalMachine.OpenSubKey(installKey); I am running a static
I have the following version being installed: Apache::SmallProf - 0.09 Apache::Registry - 2.01 Devel::SmallProf
I have following plist: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
I'm struggling with the following, in a entity class I have a preUpdate lifeCycleCallback
In Structure map I have the following line working with domain events: public void

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.