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

  • Home
  • SEARCH
  • 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 7495581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:13:26+00:00 2026-05-29T18:13:26+00:00

Where can I find the ArrayObject’s complete source code (in PHP)? What I dont

  • 0

Where can I find the ArrayObject’s complete source code (in PHP)?

What I dont understand is why you can use the “arrow” when add an element to your ArrayObject, for example:

$a = new ArrayObject();
$a['arr'] = 'array data';                             
$a->prop = 'prop data';  //here it is

You can see $a->prop = 'prop data'; is used.

Is there any magic method or what was used, and how PHP knows for example that $a['prop'] and $a->prop means the same ? (in this context)

  • 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-29T18:13:29+00:00Added an answer on May 29, 2026 at 6:13 pm

    Yes, it is magic and it can be accomplished directly in PHP. Take look at Overloading http://www.php.net/manual/en/language.oop5.overloading.php

    You can use __get() and __set in a class to do this. To make objects behave like arrays, you have to implement http://www.php.net/manual/en/class.arrayaccess.php

    This is my example code:

    <?php
    class MyArrayObject implements Iterator, ArrayAccess, Countable
    {
        /**  Location for overloaded data.  */
        private $_data = array();
    
        public function __set($name, $value)
        {
            $this->_data[$name] = $value;
        }
    
        public function __get($name)
        {
            if (array_key_exists($name, $this->_data)) {
                return $this->_data[$name];
            }
    
            $trace = debug_backtrace();
            trigger_error(
                'Undefined property via __get(): ' . $name .
                ' in ' . $trace[0]['file'] .
                ' on line ' . $trace[0]['line'],
                E_USER_NOTICE);
            return null;
        }
    
        /**  As of PHP 5.1.0  */
        public function __isset($name)
        {
            return isset($this->_data[$name]);
        }
    
        /**  As of PHP 5.1.0  */
        public function __unset($name)
        {
            unset($this->_data[$name]);
        }
    
        public function offsetSet($offset, $value) {
            if (is_null($offset)) {
                $this->_data[] = $value;
            } else {
                $this->_data[$offset] = $value;
            }
        }
    
        public function offsetExists($offset) {
            return isset($this->_data[$offset]);
        }
    
        public function offsetUnset($offset) {
            unset($this->_data[$offset]);
        }
    
        public function offsetGet($offset) {
            return isset($this->_data[$offset]) ? $this->_data[$offset] : null;
        }
        public function count(){
            return count($this->_data);
        }
        public function current(){
            return current($this->_data);
        }
        public function next(){
            return next($this->_data);
        }
        public function key(){
            return key($this->_data);
        }
        public function valid(){
            return key($this->_data) !== null;
        }
        public function rewind(){
            reset($this->_data);
        }
    }
    

    Instead of current($a), next($a) use $a->current(), $a->next()

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

Sidebar

Related Questions

You can find it here. I'm trying to understand his sample code in order
You can find the source code demonstrating this issue @ http://code.google.com/p/contactsctp5/ I have three
I can find the definition files at http://www.php.net/~helly/php/ext/spl/... but I want to extend DirectoryIterator
I can find some articles on how to use them but I can't seem
Can someone tell me where I can find the initial code, Linus Torvalds shared
you can find a similar question here PHP Post Request inside a POST Request
I can find tutorials about mapping textures to polygons specifying vertices etc. but nothing
I can find lots of information on how Long Polling works (For example, this
I can find a direct table foreign key in c# like: foreach (ForeignKey key
How can find max of three numbers in XSL ? More Information : I

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.