Page 1 of 1

Unbalanced includes

Posted: Thu Feb 08, 2007 6:59 pm
by Hak Foo
I originally got into PHP for the include statement-- factoring out common code to make cleaner pages.

Now, I'm actually trying to do some moderate lifting. I have a group of pages which are going to have a common structure as follows:

Code: Select all

if (user is logged in and administrator) {
   show administrative tool
}
else {
   chastise user for being in administrative area
}
So my desire was to break put everything up to the first { in an include, and from the first } in another include, so I could just say

Code: Select all

<?php include ("top.php");?>
    /*Show Administrative Tool Here*/
<?php include ("bottom.php");?>
The code works exactly as expected if NOT done in includes. But the moment I pull it out into includes, it bombs, complaining that found a premature $ (end of file?) in top.php.

It appears that an include has to be a balanced chunk of PHP code which could stand on its own.

Is there a workaround, or will I be forced to keep the logic in each of the pages?

Thanks for any assistance

Posted: Thu Feb 08, 2007 8:01 pm
by superdezign
You mean sending variables from page to page using includes?

I believe there is a scope issue in that case, but I've never really looked into it.

Posted: Thu Feb 08, 2007 8:24 pm
by abeall
Yeah, includes don't work how I expected them to, either. Can we see the actual code?

Posted: Thu Feb 08, 2007 8:24 pm
by nickvd
I'm not sure if I understand you correctly..

Are you saying you put

Code: Select all

if (this is true) {
in one file, and

Code: Select all

}else { //do this stuff}
in another?

If I'm right, then you cant split logic like that in different files, if you want an if/else block, it MUST be contained in the same file...

Posted: Thu Feb 08, 2007 8:39 pm
by superdezign
Oh, are you saying you put the braces INTO the files? The braces define the blocks of code. You can't separate them in any coding language. You can put your include() within the braces, but not the braces within the include. That's strange coding practice.

Posted: Thu Feb 08, 2007 8:48 pm
by abeall
You can't separate them in any coding language.
You can in ActionScript, the bane of my existence.

Posted: Thu Feb 08, 2007 8:50 pm
by superdezign
I defend ActionScript all the time, and then someone comes along and has been corrupted by it. Don't worry, it's not just you. I personally learned C++ before ActionScript, so I never dealt with the inconsistencies. Sorry you had to.

Posted: Thu Feb 08, 2007 8:58 pm
by abeall
I learned ActionScript before I learned HTML or even heard of CSS(as hard as that might be to believe, I had a very weird start in web technology), I think you could call me corrupted beyond repair ;-) I do love Flash, though.
</rabbit:trail>

Posted: Thu Feb 08, 2007 9:03 pm
by superdezign
Flash = 'awesome'; But before HTML? You could make the Flash, but had no idea how to put it onto a page? :-p

That's useless information. You may still have some learning to do.

Posted: Thu Feb 08, 2007 9:19 pm
by abeall
Sure, I knew how:
a) Give it to a developer, they'll make it work
b) Use File > Publish
c) Use Dreamweaver Insert Flash
(Ever wonder why there's so much horrible markup out there? Choose b) and c) )

Needless to say, I *started* learning AS before HTML. I learned HTML (the whole 30 seconds it takes to understand about tags) a couple weeks after I started using basic AS. Why are we talking about this? Why am I talking about this?? I'm sure there's a rule against it in those guidelines I was supposed to read.

Did you get your problem fixed, Hak Foo?