A newbie's question about variables in PHP

General discussions related to php

Moderators: macek, egami, gesf

Post Reply
User avatar
Barrikor
New php-forum User
New php-forum User
Posts: 16
Joined: Sun Dec 12, 2010 3:14 pm

Re: A newbie's question about variables in PHP

Post by Barrikor » Sat Dec 08, 2012 9:26 pm

while ($file = readdir($dp))

It's using = instead of == inside the condition. When you use = in a condition, the condition evaluates if the variable is true or false. It's really easy to accidentally create an infinite loop that way. Also if anyone sees it they usually assume that you typed it wrong and meant == instead, so if you use it you should add a comment to it.

In this case it kinda works since readdir() returns false when it's done reading the dir, BUT the example section of the documentation for readdir() clearly states not to do it this way.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests