dseguy, French
@dseguy@phpc.social avatar

TIL you can get the following error message :

"Cannot add element to the array as the next element is already occupied"

How?

dseguy,
@dseguy@phpc.social avatar

An array is full when there are no more available index. When appending, creates the next index by adding 1 to the current maximum one.

So start with PHP_INT_MAX as a key, use an append and you'll get the error.

https://3v4l.org/lvj9d

SenseException,
@SenseException@phpc.social avatar

@dseguy The error message is really weird. I'd expect a message similar to .
https://3v4l.org/9p1Hr

dseguy,
@dseguy@phpc.social avatar

@SenseException Yes, this makes more sense when one read it.

lewiscowles1986,
@lewiscowles1986@phpc.social avatar

@dseguy what are folks doing wrong, if they are storing arrays of PHP_INT_MAX size?

Much beyond 10,000; I'd start to ask more impatiently, if maybe, perhaps it might be more appropriate to deal with algorithms and structures; designed for that volume of data.

dseguy,
@dseguy@phpc.social avatar

@lewiscowles1986 I agree when reaching that level, on a 64bits machine 😨 , there must be other problems that will pop up before.

The error message is amusing, I think.

arnan,

@dseguy Should've used array_push. It adds things to the end 🤣
(Dunno if that's a real fix)

dseguy,
@dseguy@phpc.social avatar

@arnan Worth a try, but same error.

is trying to make those features with different syntax, homogenous. You may still find some missed opportunities, so it's important to check them.

alessandrolai,
@alessandrolai@phpc.social avatar

@dseguy array access to a readonly property?

dseguy,
@dseguy@phpc.social avatar

@alessandrolai Nice try. Readonly has precedence in this case, and it yields another crytpic message :

'Cannot indirectly modify readonly property x::$array'

https://3v4l.org/a6qTd

merms,
@merms@mastodon.social avatar

@dseguy Googled it because I wanted to know if I could realistically have figured it out. I feel dumb now.

dseguy,
@dseguy@phpc.social avatar

@merms With the answer in hand, I think the message might be more explicit.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • php
  • thenastyranch
  • magazineikmin
  • osvaldo12
  • tacticalgear
  • InstantRegret
  • Youngstown
  • slotface
  • rosin
  • love
  • kavyap
  • ngwrru68w68
  • mdbf
  • modclub
  • DreamBathrooms
  • Leos
  • khanakhh
  • GTA5RPClips
  • cisconetworking
  • everett
  • Durango
  • cubers
  • tester
  • provamag3
  • anitta
  • ethstaker
  • normalnudes
  • megavids
  • JUstTest
  • All magazines