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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:38:11+00:00 2026-05-13T20:38:11+00:00

Which PHP SPL interface allows objects to do this: $object->month = ‘january’; echo $object[‘month’];

  • 0

Which PHP SPL interface allows objects to do this:

$object->month = 'january';
echo $object['month']; // january

$record['day'] = 'saturday';
echo $record->day; // saturday

e.g. such as in libraries like Doctrine (Doctrine_Record)

how do I implement this? I’ve tried using ArrayObject, but they don’t behave as I thought they would.

i.e.

$object = new ArrayObject();
$object['a'] = 'test';
$object['a'] == $object->a; // false

EDIT:

I tried a barebone implementation that I called Arrayable.

class Arrayable implements ArrayAccess
{
    protected $container = array();

    # implement ArrayAccess methods to allow array notation 
    # $object = new Arrayable();
    # $object['value'] = 'some data';

    function offsetExists($offset)
    {
        return isset($this->container[$offset]);
    }

    function offsetGet($offset)
    {
        return $this->container[$offset];
    }

    function offsetSet($offset, $value)
    {
        $this->container[$offset] = $value;
    }

    function offsetUnset($offset)
    {
        unset($this->container[$offset]);
    }

    # now, force $object->value to map to $object['value'] 
    # using magic methods

    function __set($offset, $value)
    {
        $this->offsetSet($offset, $value);
    }

    function __get($offset)
    {
        return $this->offsetGet($offset); 
    }
}
  • 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-13T20:38:11+00:00Added an answer on May 13, 2026 at 8:38 pm

    It’s ArrayAccess

    See the sourcecode for Doctrine_Record

    abstract class Doctrine_Record 
        extends Doctrine_Record_Abstract 
        implements Countable, IteratorAggregate, Serializable
    

    and Doctrine_Record_Abstract

    abstract class Doctrine_Record_Abstract extends Doctrine_Access
    

    and finally Doctrine_Access

    abstract class Doctrine_Access 
        extends Doctrine_Locator_Injectable 
        implements ArrayAccess
    

    From DocBlock

    Provides array access and property overload interface for Doctrine subclasses


    An object implementing ArrayAccess has to have these methods

    abstract public boolean offsetExists  ( mixed $offset  );
    abstract public mixed offsetGet ( mixed $offset );
    abstract public void offsetSet ( mixed $offset , mixed $value );
    abstract public void offsetUnset ( mixed $offset );
    

    There is a basic usage example in the PHP manual (linked above)

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

Sidebar

Related Questions

I have this welcome.php which the administrator is redirected when he is authenticated, i
I have PHP script, which is requested by user. In this script I want
I'm not sure which php function to use for this.. How can I check
What I'm trying to find out is which php function allows me to remove
I am making a script in which php will fwrite and it ads it
I'm currently into studying wordpress files structure. Which PHP file or PHP files are
I have a function in PHP which calculates the distance between two places. Here
I have a project which uses php's mt_rand() to generate different random integers but
I have a ecrtst.php which has 3 fields for input, on submit - submit-ecr.php.
I have an index.php file which has 2 included files require(stats.php); require(stats_encry.php); stats.php which

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.