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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:22:52+00:00 2026-05-28T01:22:52+00:00

Problem: ArrayObject works as expected when the values are set or read manually, but

  • 0

Problem:

ArrayObject works as expected when the values are set or read manually, but when using a function (foreach for example) to iterate over it, things gets wicked.

It doesn’t call the offset* methods that I have defined but instead uses the ArrayIterator methods.

Code:

The Class:

class obsecureArray extends ArrayObject {


    public function offsetSet($name, $value) {
        call_user_func_array(array('parent', __FUNCTION__), array(base64_encode($name), base64_encode($value)) );
    }

    public function offsetGet($name) {
        return base64_decode( call_user_func_array(array('parent', __FUNCTION__), (array) base64_encode($name) ) );
    }

    public function offsetExists($name) {
        return call_user_func_array(array('parent', __FUNCTION__), (array) base64_encode($name) );
    }

    public function offsetUnset($name) {
        return call_user_func_array(array('parent', __FUNCTION__), (array) base64_encode($name) );
    }
}

Usage Example:

$a = new obsecureArray();
$a['test'] = 'Value';
$a[2] = '1';

define('BR','<br />');
echo 'test: ',$a['test'],BR,'2: ',$a[2],BR;

foreach($a as $key => $value)
    echo 'Key: ',$key,' Value:',$value,BR;

Output:

test: Value
2: 1
Key: dGVzdA== Value:VmFsdWU=
Key: Mg== Value:MQ==

CodePad example.

  • 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-28T01:22:53+00:00Added an answer on May 28, 2026 at 1:22 am

    I look into the ArrayObject __construct method documentation and found the third argument related to my problem:

    iterator_class:

    Specify the class that will be used for iteration of
    the ArrayObject object. ArrayIterator is the default class used.

    Now I could extended an ArrayIterator with my own offset* methods and pass it to my the constructor of ArrayObject, So I looked into ArrayIterator and it was almost identical to the ArrayObject except that it wasn’t using an external iterator obviously. So All I had to do was extend ArrayIterator instead. and had to override the current and key method as well.

    So that I have:

    class obsecureArray extends ArrayIterator {
    
        public function offsetSet($name, $value) {
            call_user_func_array(array('parent', __FUNCTION__), array(base64_encode($name), base64_encode($value)));
        }
    
        public function offsetGet($name) {
            return base64_decode(call_user_func_array(array('parent', __FUNCTION__), (array) base64_encode($name)));
        }
    
        public function offsetExists($name) {
            return call_user_func_array(array('parent', __FUNCTION__), (array) base64_encode($name));
        }
    
        public function offsetUnset($name) {
            return call_user_func_array(array('parent', __FUNCTION__), (array) base64_encode($name));
        }
    
        public function key() {
            return base64_decode(parent::key());
        }
    
        public function current() {
            return base64_decode(parent::current());
        }
    
    
    
    }
    

    and it works perfectly as expected.

    and for:

    $a = new obsecureArray();
    $a['test'] = 'Value';
    $a[2] = '1';
    
    define('BR','<br />');
    echo 'test: ',$a['test'],BR,'2: ',$a[2],BR;
    
    foreach($a as $key => $value)
        echo 'Key: ',$key,' Value:',$value,BR;
    

    I got:

    test: Value
    2: 1
    Key: test Value:Value
    Key: 2 Value:1
    

    CodePad example

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

Sidebar

Related Questions

Problem Partically solved: please read bottom The variadic function in question, stripped down to
Problem: I can set the exposureMode property of AVCaptureDevice, but it does not stay
Problem Why would compiling a program which has an int main(void) main function differ
Problem: returns array, but not in json. Result: must return array with in array.
Problem: I have two spreadsheets that each serve different purposes but contain one particular
I'm using the jHTMLArea editor, and I'm having a problem with populating my textarea
The following code fragment does nothing, but illustrates the problem. It was extracted from
Problem: I'm attempting to disable a radio button by using the code below. This
Problem I have a Silverlight 5 application using the treeview from the SDK. Now
Due to the problem I posted here Mootools when using For(...in Array) problem about

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.