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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:16:58+00:00 2026-06-18T06:16:58+00:00

I have an object that implements the ArrayableInterface (BTW, it’s from Laravel’s Eloquent ORM).

  • 0

I have an object that implements the ArrayableInterface (BTW, it’s from Laravel’s Eloquent ORM).

This object is $articles. So naturally, I can do this:

foreach ($articles as $article)
    echo $article->title . "<br/>";

But I can’t do this:

shuffle($articles);

I get the shuffle() expects parameter 1 to be array, object given warning.

  • 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-18T06:16:59+00:00Added an answer on June 18, 2026 at 6:16 am

    No, it’s not a bug.

    PHP 5 allows you to use foreach() to loop through objects that aren’t arrays. These objects are called Iterators.

    Unfortunately, the old array-based functions, like shuffle() cannot process Iterators.

    The main reason for this is that an Iterator may not even be sortable — for example, you can have iterators that read directly from a file or a URL, and read a new line of data each time the foreach() loop cycles. This clearly can’t be sorted because it’s read during the foreach() process.

    You can convert an Iterator into an array, using the cleverly named iterator_to_array() function. However, this may be a bad idea if you don’t know how much data the iterator is going to process, as you may find it uses a lot of memory.

    Some iterators may provide methods within the iterator object itself for sorting or filtering the data. If so, this is a better solution than trying to sort it as an array.

    If you’re working with an ORM, then this implies that your Iterator object is reading data from a DB. In this case, sorting it via the DB query (ie ORDER BY or whatever methods the ORM provides to do that) would probably be a better solution than sorting the data in PHP.

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

Sidebar

Related Questions

so in Objective-C I can have a reference to object that implements certain protocol
I have an object that looks like this: [Bindable] public class MyRecord implements ValueObject
How can I have a type reference that refers to any object that implements
I have an object that implements an interface. I want to call on the
I have a object that implements the IEditableObject interface exposed on a viewmodel bound
When you have an object that implements countable interface should you use $object->count() or
So I have an object that implements INotifyPropertyChanged, and I have a property that
I want to have a generic object that implements an interface. I mean if
An interesting question arose today. Let's say I have a .NET object that implements
I have an object that implements the interface Windows::Storage::Streams::IBuffer , and I want to

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.