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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:55:48+00:00 2026-06-09T16:55:48+00:00

The PHP documentation is not very explicit and only states that: SplObjectStorage::offsetExists Checks whether

  • 0

The PHP documentation is not very explicit and only states that:

SplObjectStorage::offsetExists Checks whether an object exists in the storage. (PHP >= 5.3.0)

SplObjectStorage::contains Checks if the storage contains the object provided. (PHP >= 5.1.0)

Which pretty much seems the same thing to me.

QUESTION: Apart from offsetExists being only available in 5.3.0, what is the difference between the 2?


small test I conducted…

$s = new SplObjectStorage();
$o1 = new StdClass();
$o2 = new StdClass();
$o3 = "I'm not an object!";
$s->attach($o1);

var_dump($s->contains($o1));
var_dump($s->offsetExists($o1));
echo '<br>';
var_dump($s->contains($o2));
var_dump($s->offsetExists($o2));
echo '<br>';
var_dump($s->contains($o3));
var_dump($s->offsetExists($o3));

output:

boolean true
boolean true

boolean false
boolean false

Warning: SplObjectStorage::contains() expects parameter 1 to be object, string given in index.php on line 15
null

Warning: SplObjectStorage::offsetExists() expects parameter 1 to be object, string given in index.php on line 16
null
  • 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-09T16:55:49+00:00Added an answer on June 9, 2026 at 4:55 pm

    They are both exactly the same.

    offsetExists is defined as a method alias of contains and is included simply for compliance with the ArrayAccess interface.

    You can see for yourself in the source that SPL_MA (method alias) is being used, and also that there are a couple of other aliases set up.

    • offsetExists = contains
    • offsetSet = attach
    • offsetUnset = detach
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The documentation here is not very clear: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing&s[]=editurl#saverow Do I have to manually make
I'm looking at PHP date() documentation and thought that 'I' would tell me whether
I've got this bit of php here that is very sluggish. Not millisecond sluggish,
The documentation on php.net is very spotty about causes of failure for APC writes.
Warning: very outdated question with an awful idea. Storing code, whether it be PHP,
I'm in the process of setting up a php project, but am not very
In the php documentation listed here there's an indication that the function uses the
The PHP documentation says the following about the __call() magic method: __call() is triggered
On the php documentation,i found this note: On both 32 and 64-bit systems (OS
As shown in the php documentation is it possible to create your own exception

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.