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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:11:15+00:00 2026-06-14T08:11:15+00:00

normally using java. I ve seen a snippet like this today $oStrategie = new

  • 0

normally using java. I ve seen a snippet like this today

$oStrategie = new Strategie();

foreach($aData as $key=>$value) {
        $oStrategie[$key] = $value;
}

$oStrategie->doSomething()

Strategie is a selfmade php class with nothing special. simple constructor doing nothing important and so on.

in the class Strategie the method doSomething() accesses the ArrayValues of $aData

$this['array_index_1'] 

Why can i access the array there even if the Strategie class doesent have any attributes defined and no setter overwritten or something like that? Can anybody explain me whats happening there? Is there no need to have attributes in the class in php???

  • 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-06-14T08:11:16+00:00Added an answer on June 14, 2026 at 8:11 am

    Your class implements the ArrayAccess interface. This means it implements the following methods:

    ArrayAccess {
        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 )
    }
    

    This allows you to use array access $var[$offset] on instances of this class. Here’s a standard implement of a class like this, using a $container array to hold properties:

    class Strategie implements ArrayAccess {
    
        private $container = array();
    
        public function __construct() {
            $this->container = array(
                "something"   => 1,
            );
        }
        public function offsetSet($offset, $value) {
            if (is_null($offset)) {
                $this->container[] = $value;
            } else {
                $this->container[$offset] = $value;
            }
        }
    
        public function offsetExists($offset) {
            return isset($this->container[$offset]);
        }
    
        public function offsetUnset($offset) {
            unset($this->container[$offset]);
        }
    
        public function offsetGet($offset) {
            return isset($this->container[$offset]) ? $this->container[$offset] : null;
        }
    }
    

    Without looking at the actual implementation of Strategie or the class it’s derived from, it’s hard to tell what it’s actually doing.

    But using this, you can control the behavior of the class, for example, when accessing an offset that doesn’t exist. Suppose we replace offsetGet($offset) with:

    public function offsetGet($offset) {
        if (isset($this->container[$offset])) {
            return $this->container[$offset];
        } else {
            Logger.log('Tried to access: ' + $offset);
            return $this->default;
        }
    }
    

    Now whenever we try to access an offset that doesn’t exist, it will return a default (eg: $this->default) and log an error, for example.

    Note that you can accomplish similar behavior using the magic methods __set(), __get(), __isset() and __unset(). The difference between the magic methods I just listed and ArrayAccess is that you’d access a property via $obj->property rather than $obj[offset]

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

Sidebar

Related Questions

Normally, I'll start jetty (version 8) using this: java -jar -Xms1024m -Xmx1024m -server -XX:+UseConcMarkSweepGC
when I'm using a switch(in Java in this case) I normally use the default
Normally when I want to query large result set using Mysql I write this
I'm using a new set of Java tools that I'm not entirely familiar with,
So normally we can get z-Index value of a div element using, e.g: var
I am writing a Desktop GUI application in Clojure using Java Swing. Normally when
Is it possible to do method swizzling in android using java? i would like
I'm using firefox3 to run a Java Applet (on Linux). normally, when the JVM
We have a Java Applet built using AWT. This applet lets you select pictures
This is just a general question on actual thread design. I'm using Java on

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.