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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:29:19+00:00 2026-06-17T20:29:19+00:00

The below is example2 from php.net’s splobjectstorage documentation. The lines using $s[$o1] and $s[$o2]

  • 0

The below is example2 from php.net’s splobjectstorage documentation.
The lines using $s[$o1] and $s[$o2] is syntax I’m not familiar with and haven’t seen yet for objects (still learning)

Is this a standard way of fetching properties from an object that would work with any class I’ve created?

Is this instead using a magic method or additional programmed functionality to create this syntax for just this class?

<?php
// As a map from objects to data
$s = new SplObjectStorage();

$o1 = new StdClass;
$o2 = new StdClass;
$o3 = new StdClass;

$s[$o1] = "data for object 1";
$s[$o2] = array(1,2,3);

if (isset($s[$o2])) {
var_dump($s[$o2]);
}
?>

http://php.net/manual/en/class.splobjectstorage.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-17T20:29:20+00:00Added an answer on June 17, 2026 at 8:29 pm

    You can use the square bracket syntax for arrays and all classes that implement the ArrayAccess interface (which SplObjectStoragedoes).

    Example:

    class MyObjectStorage implements ArrayAccess {
        public function offsetExists($offset) {}
    
        public function offsetSet($offset, $value) {
            echo "Set $offset to $value.";
        }
    
        public function offsetGet($offset) {
            echo "Get $offset.";
        }
    
        public function offsetUnset($offset) {}
    }
    
    $list = new MyObjectStorage();
    $list['foo'] = 'bar'; // prints "Set foo to bar.";
    

    See http://php.net/ArrayAccess for more information.

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

Sidebar

Related Questions

The example below is an extráct from http://php.net/manual/de/control-structures.switch.php <?php $totaltime = 0; switch ($totaltime)
I'm trying to complete an example from php.net (code below) which allows you to
I'm trying to run the example Gearman worker from their documentation (see below), but
How to isolate specific hyperlinks from a website(using simple html dom php). for example
code is as below: <?php //set up variables $theData = '<?xml version=1.0?> <note> <to>php.net</to>
I followed the HTML5 Websocket tutorial of the website below: http://net.tutsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/ It worked well,
Is it possible to remove a string (see example below) from a PHP array
I'm using the photo slider code from here: http://tympanus.net/codrops/2010/10/07/slider-gallery/ and trying to modify it
I'm confused as to how fread() is used. Below is an example from cplusplus.com
The example below is from a REST database driver on Python 2.7. In the

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.