Unbalanced includes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Hak Foo
Forum Newbie
Posts: 1
Joined: Thu Feb 08, 2007 6:48 pm

Unbalanced includes

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
abeall
Forum Commoner
Posts: 41
Joined: Sun Feb 04, 2007 11:53 pm

Post by abeall »

Yeah, includes don't work how I expected them to, either. Can we see the actual code?
Last edited by abeall on Thu Feb 08, 2007 8:26 pm, edited 1 time in total.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post 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...
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
abeall
Forum Commoner
Posts: 41
Joined: Sun Feb 04, 2007 11:53 pm

Post by abeall »

You can't separate them in any coding language.
You can in ActionScript, the bane of my existence.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
abeall
Forum Commoner
Posts: 41
Joined: Sun Feb 04, 2007 11:53 pm

Post 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>
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
abeall
Forum Commoner
Posts: 41
Joined: Sun Feb 04, 2007 11:53 pm

Post 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?
Post Reply