Trooper Posted August 25, 2007 Share Posted August 25, 2007 Ok I have these functions inside a class called TemplateSystem: function loadTemplateFile( $filename ) { $file = file( $filename ); if( $file == false ) return null; $file = implode( " ", $file ); return $file; } function parseTemplateFile( $file ) { $file = str_replace( "%templateheader%", $this->loadTemplateFile( "style/header.html" ), $file ); $file = str_replace( "%templatefooter%", $this->loadTemplateFile( "style/footer.html" ), $file ); //$file = str_replace( "%iecheck%", tmplIECheck(), $file ); return $file; } function renderPage() { $page = $this->loadTemplateFile( "style/page.html" ); $page = $this->parseTemplateFile( $page ); $page = str_replace( "%templatecontent%", $this->contents, $page ); echo $page; } Now the way I have posted works exactly as expected. Now if I write the load function like this: function loadTemplateFile( $filename ) { $file = file( $filename ); if( $file == false ) return null; $file = implode( " ", $file ); return $this->parseTemplateFile( $file ); } ...and remove the parseTemplateFile from the renderPage function, nothing appears on the screen and the page is compleatly blank. All three functions are in the same class. I have no idea why this is. Thanks, Ryan Quote Link to comment https://forums.phpfreaks.com/topic/66686-functionoop-problem/ Share on other sites More sharing options...
MadTechie Posted August 25, 2007 Share Posted August 25, 2007 parseTemplateFile call's loadTemplateFile which is fine.. but on your change parseTemplateFile call's loadTemplateFile which call's parseTemplateFile which call's loadTemplateFile which call's parseTemplateFile Inf. Loop, Quote Link to comment https://forums.phpfreaks.com/topic/66686-functionoop-problem/#findComment-334169 Share on other sites More sharing options...
Trooper Posted August 26, 2007 Author Share Posted August 26, 2007 parseTemplateFile call's loadTemplateFile which is fine.. but on your change parseTemplateFile call's loadTemplateFile which call's parseTemplateFile which call's loadTemplateFile which call's parseTemplateFile Inf. Loop, Ohh...shouldn't it only loadTempalateFile if %templateheader% is in the file tho? Quote Link to comment https://forums.phpfreaks.com/topic/66686-functionoop-problem/#findComment-334219 Share on other sites More sharing options...
MadTechie Posted August 26, 2007 Share Posted August 26, 2007 it will get the returned data to check to see if its in their but by then the loop has started.. you could try function loadTemplateFile( $filename, $parse=true ) { $file = file( $filename ); if( $file == false ) return null; $file = implode( " ", $file ); return ($parse)?$this->parseTemplateFile($file):$file; } function parseTemplateFile( $file ) { $file = str_replace( "%templateheader%", $this->loadTemplateFile( "style/header.html", false ), $file ); $file = str_replace( "%templatefooter%", $this->loadTemplateFile( "style/footer.html", false), $file ); //$file = str_replace( "%iecheck%", tmplIECheck(), $file ); return $file; } totally untested Quote Link to comment https://forums.phpfreaks.com/topic/66686-functionoop-problem/#findComment-334225 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.