php - Strange behavior of if statement: always executing else block -


people, i'm in doubt whether me or computer slow here.

i've following coding piece:

class whatever {     ...      private function requirefile($filepath)     {         if(is_array($filepath))             foreach($filepath $singlefilepath)                 if($this->requirefile($singlefilepath))                     break;         elseif(($filepath = stream_resolve_include_path($filepath = $filepath . '.php')) !== false)             return require_once $filepath;     } } 

besides being ugly code, doesn't work expected. idea here make method accept both string , array of strings parameter and, in case of array, recurse on work on each of strings.

what happening that, when provided array parameter, both if , elseif block executed, , making php parser shout it's occurring array string conversion in elseif line.

i'm not understanding why adding brackets around if block (putting them around foreach or inside if doesn't change anything) making work charm, since there 1 statement below if , it's not needed have them there:

class whatever {     ...      private function requirefile($filepath)     {         if(is_array($filepath)) {             foreach($filepath $singlefilepath)                 if($this->requirefile($singlefilepath))                     break;         } elseif(($filepath = stream_resolve_include_path($filepath = $filepath . '.php')) !== false)             return require_once $filepath;     } } 

can me here? what's wrong in code?

edit: folks. guess answers proves me slow 1 here, hahaha. months away programming makes people write crazy stuff...

without brackets php parser parses elseif statement in relation second if, not first (outer). adding brackets tells parser elseif belongs first if.

php not python indents tells parser relation between statements.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -