Re: seperating php code from html?
| From: | Prince | Date: | Mon, 14 Apr 2003 11:43:40 +0000 |
| Subject: | Re: seperating php code from html? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-143744@lists.php.net to get a copy of this message | ||
----- Original Message -----
From: "Mike" <php-digest@custom87.net>
To: "Prince" <friendly@kaltelnet.net>
Sent: Sunday, April 13, 2003 11:57 PM> On Sun, 2003-04-13 at 19:52, Prince
wrote:
> > hi...
> >
> > i heard that it was better if when writing php to keep as much of the
php
> > code away from the html source as possible... or at least have as little
> > html code in the php scripts as possible.. but either way it goes was
just
> > told to keep the 2 apart from each other as much as possible..
> >
> > so given that fact
> >
> >
> > 1. is that a true statement i should try to follow? or doesnt it really
> > matter
> True statement, if you think that someone will ever want to make changes
> to your code who doesn't have PHP experience. Plus it makes stuff much
> cleaner. Checkout some templating engines (smarty is very good IMHO)
thats what i thought for now.. would rather write code by hand because it
gives me experience writing by what the true code and stuff is before i get
into anything else...
>
> > 2. is it ok to write code that would maybe take up 15 lines or so and
turn
> > it into 1 or 2 lines?
> Of course. Why not? Unless you mean:
> $var = "something something";
> $var2 = explode(" ",$var);
> print_r($var2);
>
> and you want to do:
> $var = "something something"; $var2 = explode(" ",$var); print_r($var2);
>
> There no reason to do that, it just makes your code messy. I don't think
> it is any faster.
i mean if i write something like this:
if(!isset($PHP_AUTH_USER)){
//do lots of code here
}else{
//do lots more code here
}
and there is a lot easier way to write that in the sense of more usefull
functions or whatever what way is best the more usefull functions or the way
i know how to write it as long as it works and i know what i wrote?
>
> > 3. is code better written where the person who wrote it and everyone
else
> > can read it or should it be written for speed ..
> >
> Not quite sure what you mean here. Comments are needed even for you,
> you'd be suprised three weeks later when you can't remember exactly why
> you wrote what. Comments make an extremely minor performance hit. Maybe
> a couple of milliseconds.
i mean if i dont understand what was written in my own code is it better
taht i write at my own understanding level instead of someone elses...
>
> > and last
> > 4. when writing a class like a db class is it normal to be able to use
1
> > line of code after writing it instead of 6 before it was writen..
(guess
> > this sort of fits in with the first thing but just making sure)...
> >
>
> Do you mean something like:
> class Person() {
> $this->age = "15";
> $this->sex = "Male";
> $this->name = "Joe";
> }
>
> $Joe = new Person;
>
> instead of
>
> $Joe_age = "15";
> $Joe_sex = "Male";
>
> etc., sure that's fine. PHP hardly takes performance hits from things
> like that. If your that worried about performance, get a php accelerator
> that caches the output of pages...
>
thats what i was sort of talking about... trying to keep all related blocks
of code in one section though would make it sort of easier to read at least
for me that is... just thought a class for db on an application i had
written would be a lot cleaner and besides if i did that most of the php
code would be contained in the main application engine and not scattered out
all over the place...
so if i had:
$member = new db;
instead of all the code (about 70 lines a entry or so)
$member->set_company("company name");
instead of the so many lines for sql queries and so on
> >
> >
>
> -Michael
>