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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:33:00+00:00 2026-05-24T11:33:00+00:00

I’ve noticed that PHP’s current() and key() array functions ( like other array-pointer functions

  • 0

I’ve noticed that PHP’s current() and key() array functions (like other array-pointer functions) take the array argument by reference:

mixed current ( array &$array )
Every array has an internal pointer to its “current” element, which is initialized to the first element inserted into the array.

After a few quick checks, it appears that both current() and key() (unlike other array-pointer functions) accept the array argument by value, thereby not throwing an error when passed the return value of a function.

I’ve concluded that it’s simply because current() and key() do not try to move the array pointer, and therefore do not require the argument be passed by reference (or do so in some transparent, quiet, secretive way). However, this is of a bit of concern to me.

Can anyone confirm if this is the intended functionality? I’d gladly use it to snatch up the first element/key of a returned array, but it seems awfully strange that PHP is allowing this when under nearly any other circumstance a fatal error (or strict standards warning) is issued for passing values to a by-reference parameter.

Feature or bug?


For instance:

error_reporting(-1);

function getArray(){
    return array('a', 'b', 'c');
}

var_dump( current(getArray()) );
var_dump( key(getArray())     );
var_dump( next(getArray())    );
var_dump( prev(getArray())    );
var_dump( reset(getArray())   );
var_dump( end(getArray())     );

Results:

string(1) "a"

int(0)

Strict standards: Only variables should be passed by reference ...
string(1) "b"

Strict standards: Only variables should be passed by reference ...
bool(false)

Strict standards: Only variables should be passed by reference ...
string(1) "a"

Strict standards: Only variables should be passed by reference ...
string(1) "c"
  • 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-24T11:33:01+00:00Added an answer on May 24, 2026 at 11:33 am

    That’s definitely a feature, and I would not want to live without it.

    Now the question is if the documentation is correct about the &.

    The code

    current

    PHP_FUNCTION(current)
    {
        HashTable *array;
        zval **entry;
    
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &array) == FAILURE) {
            return;
        }
    
        if (zend_hash_get_current_data(array, (void **) &entry) == FAILURE) {
            RETURN_FALSE;
        }
        RETURN_ZVAL(*entry, 1, 0);
    }
    

    next

    PHP_FUNCTION(next)
    {
        HashTable *array;
        zval **entry;
    
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &array) == FAILURE) {
            return;
        }
    
        zend_hash_move_forward(array);
    
        if (return_value_used) {
            if (zend_hash_get_current_data(array, (void **) &entry) == FAILURE) {
                RETURN_FALSE;
            }
    
            RETURN_ZVAL(*entry, 1, 0);
        }
    }
    

    Conclusion

    The docs are correct – the array is taken as reference in both cases.

    No idea though why on throws the error, the other not.

    Btw, the errors are thrown in

    • Zend/zend_vm_def.h
    • Zend/zend_vm_execute.h
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have some data like this: 1 2 3 4 5 9 2 6

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.