php - Is the array returned by scandir() a countable object? -


i'm trying figure out why count(scandir("/dirname")); evaluates 0 when number of files in directory not 0. when person goes onto page, following script executes @ top of page:

<?php      setcookie("user", count(scandir("/players"))); ?> 

the directory contains 2 files. count(scandir("/dirname")); still evaluates 0. because array

player0.json player1.json 

returned scandir() non countable object?

assuming directory players located in same directory php file located, can pass 'players' scandir() or other function works directories. relative path , of times works.

but, in order make sure code works, better use php magic constant __dir__ generated full path of players directory:

scandir(__dir__.'/players') 

should return array contains names of files stored in players directory , passing array count() correctly return number of values contains (as now).


to answer question in title, on success scandir() returns php array , php arrays countable.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -