Jump to content

[SOLVED] using require, require_once, include, etc... but if and else interuption


programguru

Recommended Posts

i am facing a strange issue which is new to me, and i have been unable to resolve for some days now. i ran various tests and read the manuals but this "issue" i am having was not covered.

 

i am assuming it is something i am doing incorrect, but nothing is adding up.

 

first off i am very familiar with the require_once function, and use it all the time, so here is what's happening:

 

i am including a file into my main static php page. the file i am including has and if and else which the closing bracket for the else statement is in the static file.

 

i have tested the file in full w/out the require_once, include, etc... and it works perfect, but any way i try this with the including i get the following standard "wrong place!" error.

 

Parse error: syntax error, unexpected $end in C:\www\inc\header.php on line 70

 

 

and im sure the include is working because the line number 70 is correct (when the include file and static file lines are counted) in the error, so the file is surely being pulled in.

 

does anyone know if i am just screwing up the whole point? or totally missing something here? is it a known bug?

 

 

You cannot split a language construct like an if/else statement with part of it in an include file and part of it in the main file.

 

PFMaBiSmAd , thanks for the easy answer. I was beating myself up on experiments, and truthfully it was hard to believe it was not possible. Is this documented in the manual somewhere that you are aware of? I could not find it on php.net.

 

Maybe php 7 will be more kind to if/else includes!

 

 

Whatever you think your application needs by splitting the syntax of one statement between a main file and an include file is the wrong approach. Find a different way of organizing your logic.

Whatever you think your application needs by splitting the syntax of one statement between a main file and an include file is the wrong approach. Find a different way of organizing your logic.

 

What I am doing is very unique, and it's not usual to try something like this. But I would be interested in the correct "logic". Please elaborate in detail a better method?

 

I am not sure how anyone would know the logic is "bad" if they have no idea what I am doing in the first place.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.