Bug #74349 [Com]: cannot use include return string in OR condition

From: Date: Fri, 31 Mar 2017 12:33:09 +0000
Subject: Bug #74349 [Com]: cannot use include return string in OR condition
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-208223@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74349&edit=1 ID: 74349 Comment by: kelunik@php.net Reported by: liviu dot gelea at gmail dot com Summary: cannot use include return string in OR condition Status: Not a bug Type: Bug Package: Filesystem function related Operating System: Windows 10 PHP Version: 7.1.3 Block user comment: N Private report: N New Comment: Your logic should be: if (!file_exists($environmentFile) || !($environment = include $environmentFile)) ^ Previous Comments: ------------------------------------------------------------------------ [2017-03-31 12:27:15] requinix@php.net >|| ($environment = include $environmentFile) Your logic is backwards. ------------------------------------------------------------------------ [2017-03-31 12:24:42] liviu dot gelea at gmail dot com Description: ------------ When "returning" a string from a file, the result behaves differently if used in a condition containing the || operator setup an "environment.php" file that contains: <?php return "production"; then run the script attached: Test script: --------------- <?php // determine application environment $environmentFile = 'environment.php'; if (!file_exists($environmentFile)) { $environment = 'development'; } elseif ($environment = include $environmentFile) { // do nothing } else { $environment = 'development'; } echo $environment . " "; if (!file_exists($environmentFile) || ($environment = include $environmentFile)) { $environment = 'development'; } echo $environment; Expected result: ---------------- the script should echo the string "production production" Actual result: -------------- "production development" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74349&edit=1

« previous php.bugs (#208223) next »