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

Ask A Question

Stats

  • Questions 503k
  • Answers 503k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer One solution I've found is to create a new page… May 16, 2026 at 2:48 pm
  • Editorial Team
    Editorial Team added an answer The individual classes should be as free from infrastructure as… May 16, 2026 at 2:48 pm
  • Editorial Team
    Editorial Team added an answer The only way to this is to have a new… May 16, 2026 at 2:48 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm currently doing this: NSMutableDictionary *dict = [[NSDictionary alloc] initWithContentsOfURL: [NSURL URLWithString:@http://mysite/mypage.php]]; Which is
I saw this question asked about C# I would like an answer for PHP.
Which PHP RPC (XML or JSON) library have you successfully used? I have done
i have table question (mysql with php) which contains question,category(multiple) and subcat(multiple) its belong.
I want to draw an image in PHP, which looks like the circle in
At the beginning PHP was a scripting language. But after the introduction and improvement
I have an abstract syntax tree which I need to iterate. The AST is
I'm writing and testing a ClassLoader component, which can be instantiated many times, with
Possible Duplicate: PHP 5.3 changelog? I am new to PHP, and I am confused
I've been writing PHP applications using PHP for a while in WAMP. Now I'm

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.