Article 57Q2J php global array generates count() warning

php global array generates count() warning

by
dogpatch
from LinuxQuestions.org on (#57Q2J)
I need to define an array as global and then populate it and access it through one or more functions. So my php code looks something like:
Code:global $myarray;
.
.
$myarray = array();

function A () {
global $myarray;
.
.
$myarray($mycounter++) = "SomeValue";
.
.
}

function B {
global $myarray
.
.
$var1 = count($myarray);
.
.
}This seems to run as expected, the count() function returning the current number of elements in the array. But my error log file is always filled with warnings that ". . . count(): Parameter must be an array or an object that implements Countable. . .", referring to the line in function B that invokes count().

I've looked at many tutorials and examples, and can't see what may be wrong with my implementation. Would like to avoid these warning messages, as they make it very difficult to see any real errors that may be hidden in the bloated error log file.latest?d=yIl2AUoC8zA latest?i=LXDxztEc-9A:TtjKGWSkoWw:F7zBnMy latest?i=LXDxztEc-9A:TtjKGWSkoWw:V_sGLiP latest?d=qj6IDK7rITs latest?i=LXDxztEc-9A:TtjKGWSkoWw:gIN9vFwLXDxztEc-9A
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments