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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:43:55+00:00 2026-05-23T02:43:55+00:00

When trying to define an array such this: $array = new SPLFixedArray(256); for ($i

  • 0

When trying to define an array such this:

$array = new SPLFixedArray(256);

for ($i = 0; $i < 256; $i++) {
    $array[$i] = new SPLFixedArray(256);

    for ($j = 0; $j < 256; $j++) {
        $array[$i][$j] = new SPLFixedArray(5);

        for ($k = 0; $k < 5; $k++) {
            $array[$i][$j][$k] = 0;
        }
    }
}

I’m getting, only in CLI, “Segmentation Fault”. I read about such errors here on SO in C/C++, where is likely to be a memory problem and recommends to load everything to the heap memory with malloc(). In PHP do we have such tool?

This happens even in small 3d arrays, such as 15 instead of 256 (but works under 15).

Thanks!

  • 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-23T02:43:56+00:00Added an answer on May 23, 2026 at 2:43 am

    Only a PHP bug would segfault; you should never be able to do that. It segfaults for me on PHP 5.3.5. I see nothing in 5.3.6’s change log that would indicate it has been fixed. (It crashes on 5.3.6 for me as well.)

    As a workaround you could do this:

    $array = new SplFixedArray(256 * 256 * 5);
    $array[$i * JK + $j * K + $k] = $foo;
    

    JK and K are constants. JK = $jsize * $ksize; and K = $ksize.

    That’s likely to give you better performance than creating 3D arrays anyway.

    Update:

    I tried it on PHP 5.3.7-dev, and there is no segfault. So, fingers-crossed, it has been fixed and will work correctly in PHP 5.3.7.

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

Sidebar

Related Questions

I am trying to define dynamically variables. I am using a function for this,
I'm trying to create a array of structs, but define it's size later, like
I'm trying to understand what a JavaScript array is because traditional programming languages define
I'm trying to define an array with a list of file urls, and then
Im trying to define a dataTemplate for a business object in my wpf application
I'm trying to define a task that emits (using echo) a message when a
I'm trying to define a table to store student grades for a online report
I am trying to define a WCF contract that returns an interface, something like
I'm trying to dynamically define functions that call through to another function that takes
I am trying to figure out how to define a function that works on

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.