php slump
Moderator: General Moderators
php slump
Hey guys ** first post **
I’ve hit a slump in php... I’ve read a few books on it, programmed a few things to test my knowledge on getting and outputting from database..., I understand the logic of php programming... but this is where I go wrong... I’ve got enough knowledge to tackle a big project like a full blown website, I got a pretty good login coded.... but this is where I go wrong...
I need to understand how to use classes in a real world website scheme; I need to understand OPP and how it can help me out... I need to learn the power of classes cause these dumb examples I see over the internet about a class to turn on a car, and a function to turn it on and off and a return to the main program with a variable is not helping me implement into a real website environment.
This is what I need to know.... how to use classes to drive me whole website, how to use proper template, how to break a template down and if I have a module handling my template where initially do I call module? Do you call it in the template? Also I would need to know the power of a proper website structure so I can plan this full blown project out and I need to consider things like pagination and such.....
Personally I think the step from taking php into classes and using them to your advantage is one of the hardest steps in design I’m going to take.., and I need some help to get through it...
so basically what I’m asking , how do I plan a proper php project from ground up... what elements should I consider... how in-depth should a good site get....
(online resources or user input is best)
I’ve hit a slump in php... I’ve read a few books on it, programmed a few things to test my knowledge on getting and outputting from database..., I understand the logic of php programming... but this is where I go wrong... I’ve got enough knowledge to tackle a big project like a full blown website, I got a pretty good login coded.... but this is where I go wrong...
I need to understand how to use classes in a real world website scheme; I need to understand OPP and how it can help me out... I need to learn the power of classes cause these dumb examples I see over the internet about a class to turn on a car, and a function to turn it on and off and a return to the main program with a variable is not helping me implement into a real website environment.
This is what I need to know.... how to use classes to drive me whole website, how to use proper template, how to break a template down and if I have a module handling my template where initially do I call module? Do you call it in the template? Also I would need to know the power of a proper website structure so I can plan this full blown project out and I need to consider things like pagination and such.....
Personally I think the step from taking php into classes and using them to your advantage is one of the hardest steps in design I’m going to take.., and I need some help to get through it...
so basically what I’m asking , how do I plan a proper php project from ground up... what elements should I consider... how in-depth should a good site get....
(online resources or user input is best)
If you haven't been programming long, then the last thing you need to do is jump into OO. Especially if this (PHP) is your first language. In order to be a truly good programmer, you need to understand some foundation stuff. Algorithms, data structures, memory allocation, etc.... It's possible to take the OO route right now and still be a good programmer, but you'll allways be at a loss when you start to consider issues relating to low level 'under-the-hood' operations and how they effect high level scripting languages like PHP.
One option would be to take both routes. Learn C or Pascal. Not C++ or Object Pascal. Do some research on algorithms and data structures and try to pay attention to some of the conversation on the PHP internals list. The more you chew, the more you understand.
Cheers
One option would be to take both routes. Learn C or Pascal. Not C++ or Object Pascal. Do some research on algorithms and data structures and try to pay attention to some of the conversation on the PHP internals list. The more you chew, the more you understand.
Cheers
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
A big question mark goes to BDKR. You now need C++ to program in PHP? 
OOP in PHP (same as OOP in anything else) requires an understanding of what OOP is, how it works, how its most effectively used. The best way to get those three pieces is both through reading (a basic PHP introductory book for PHP5 is a great start) and practical experience (you need to make a few small - SMALL
- OOP programs).
Stuff like memory allocation in PHP is moot - you don't handle it in PHP other than keeping your scripts tidy, efficient (things like knowing the speed difference between ereg_replace, preg_replace, and str_replace), and not requiring a tin of code to do small things. This is a whole other area - and not all that important to understanding OOP basics IMHO.
The main difficulty in OOP is making that leap to knowing what an object is, and what it does. Think of it this way.
An object is a box. Inside the box are properties (variables) and methods (functions). So a simple box for a User lets say may have three properties:
These like any variable store values.
Our User object may also have three methods:
Lets say these are all database functions - create a record, update a record, delete a record.
To use: First you add these to a class - the text inside a PHP file.
You now have a re-usable class. If you needed to manipulate 3 users, you would just have to instantiate (create) 3 new objects from this class. e.g.
Pretty simple huh? 
Now one area you can also look up (which is useful again for OOP in most languages) are Design Patterns. Jason Sweat has a pretty good PHP introduction to these over on phpArchitect (not a marketing plug - but there are few PHP books on the topic).
These focus on how objects work together, and address very common problems in PHP which have commonly used OOP solutions. These patterns make OOP use a lot easier - and I dare say understandable once you can recognise them all.
Other OOP practices you'll come across with experience. You could for example in the above separate the data properties into one class, and the methods into another. The use would then be more like:
I definitely got carried away on this post
Hopefully it sheds a little light until you get that PHP Book and get to more in-depth OOP material. Have fun!
OOP in PHP (same as OOP in anything else) requires an understanding of what OOP is, how it works, how its most effectively used. The best way to get those three pieces is both through reading (a basic PHP introductory book for PHP5 is a great start) and practical experience (you need to make a few small - SMALL
Stuff like memory allocation in PHP is moot - you don't handle it in PHP other than keeping your scripts tidy, efficient (things like knowing the speed difference between ereg_replace, preg_replace, and str_replace), and not requiring a tin of code to do small things. This is a whole other area - and not all that important to understanding OOP basics IMHO.
The main difficulty in OOP is making that leap to knowing what an object is, and what it does. Think of it this way.
An object is a box. Inside the box are properties (variables) and methods (functions). So a simple box for a User lets say may have three properties:
Code: Select all
var $userID;
var $userName;
var $userEmail;Our User object may also have three methods:
Code: Select all
function deleteUser() {...}
function updateUser() {...}
function createUser() {...}To use: First you add these to a class - the text inside a PHP file.
Code: Select all
class User (
var $userID;
var $userName;
var $userEmail;
function User($details) {
$this->userID = $details['id']; // typically this is empty since MySQL can autoincrement the ID automatically or PostgreSQL can use the SERIAL field type for sequences.
$this->userName = $details['name'];
$this->userEmail = $details['email'];
}
function createUser() {...}
function updateUser() {...}
function deleteUser() {...}
)Code: Select all
$john = array(1, 'John', 'john@example.com');
$paddy = array(1, 'Paddy', 'paddy@example.com');
$yoda = array(1, 'Yoda', 'yoda@example.com');
$user1 = new User($john);
$user2 = new User($paddy);
$user3 = new User($yoda);
// now have three objects representing 3 users and all their details, and with methods to create/update/delete their records on the database.
// create a record for John
$user1->createUser();
// change Johns email and update
$user1->email = 'john2@example.com';
$user1->updateUser();
// can do the same for all other Users with a representing object.Now one area you can also look up (which is useful again for OOP in most languages) are Design Patterns. Jason Sweat has a pretty good PHP introduction to these over on phpArchitect (not a marketing plug - but there are few PHP books on the topic).
These focus on how objects work together, and address very common problems in PHP which have commonly used OOP solutions. These patterns make OOP use a lot easier - and I dare say understandable once you can recognise them all.
Other OOP practices you'll come across with experience. You could for example in the above separate the data properties into one class, and the methods into another. The use would then be more like:
Code: Select all
$yoda = array(1, 'Yoda', 'yoda@example.com');
$user1 = new User($yoda);
$methods = new UserDatabaseMethods(); // our methods are here
// remember objects are boxes, you can put one box into another just like passing a variable as a parameter to a function
$methods->createUser($user1);
// change Johns email and update
$user1->email = 'yoda2@example.com';
$methods->updateUser($user1);- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
Before my rambling lost all control on the last reply...so basically what I’m asking , how do I plan a proper php project from ground up... what elements should I consider... how in-depth should a good site get....
As PJ states you don't need OOP for a website. But when that website is a) dynamic and b) large, OOP can keep it organised more efficiently than without - as a general rule. Not commenting on large procedural based web applications other than to note my experience has been they are monsters to maintain and extend.
I suppose one example, that's only started up really, and is open source - is something I work on. Not sure of its value as a something to research and look into, its a hobby project. http://www.quantum-star.com
This is a small MVC type OOP design - only the installer works so its pretty basic and very small - not much reading to it.
It might make more sense once you read up on the OOP basics, and it uses a few design patterns like FrontController which may make sense. Think of it as a puzzle box to figure out maybe.
Anyone else have a open source website type app of a similar small size? Don't think the guy needs a massive thing like a PHP framework or other large scale web app.
Re: php slump
Other forumites have answered your OOP question, so I'll tackle this.stador1 wrote:so basically what I’m asking , how do I plan a proper php project from ground up... what elements should I consider... how in-depth should a good site get....
A project should be as in-depth as it needs to be, and no more.
To create a site (for me, client sites go faster) I generally approach it in roughly this order:
1. Have an idea.
2. List all the features I want in the site.
3. Wait a few days.
4. Read my list back. Cross out the stupid features, add in the stuff I missed.
5. Repeat steps 3 and 4 a few times.
6. Most of the time I've now discarded the idea and thought of something better. Go to step 2.
7. Expand on my list of features writing down everything that they should do.
8. Go through my list of features and develop a database schema based on it. Try to think of every possible bit of data that will be required.
9. Create database.
10. Make a list of objects/functions that will be required to access/insert/update the data in the site.
11. Build objects/functions.
Only at this point in time do I start writing any forms, front end code, admin code, creating images, etc. This is usually about 3 or 4 weeks in. I approach projects with an extremely data-centric view. If you can get the data side of things right from the beginning then everything else is easy. There's nothing more complicated than getting a couple of weeks into coding a site and realising you need a cross-reference table or an extra field or soemthing that you missed at the start. Planning is absolutely critical.
Unfortunately I find this approach rarely works on client sites. They always want to see something working a week or two in so you have to approach things a little differently. Fortunately most of my clients all want roughly the same sort of sites so the planning side of things is usally done already. There's only so many times you can analyse the requirements of a contact form.
thx onion2k and Maugrim_The_Reaper, OOP really makes sense now.... and thx for helping me plan out my project....and ill be sure to check out that book.
also, if any of you have websites you all want me to check out like other communties, tut sites... or whatever it would be appreciated.. but i thinik asked for enough and got enough in return.., i think i'm ready to tackle this project.
also in response to the first few post.. ive done alot turing thru the years, and i'm learning c sharp soon, but thx for tellin em about the foundation of high level languages...
also, if any of you have websites you all want me to check out like other communties, tut sites... or whatever it would be appreciated.. but i thinik asked for enough and got enough in return.., i think i'm ready to tackle this project.
also in response to the first few post.. ive done alot turing thru the years, and i'm learning c sharp soon, but thx for tellin em about the foundation of high level languages...
Did I say that? Is that pot I smell? Go back and really read what I said.Maugrim_The_Reaper wrote: A big question mark goes to BDKR. You now need C++ to program in PHP?![]()
You know, I agree with this, but then nothing I said contradicited this anyway.Maugrim_The_Reaper wrote: OOP in PHP (same as OOP in anything else) requires an understanding of what OOP is, how it works, how its most effectively used. The best way to get those three pieces is both through reading (a basic PHP introductory book for PHP5 is a great start) and practical experience (you need to make a few small - SMALL- OOP programs).
You're kidding right? What have I been doing for the last six years?Maugrim_The_Reaper wrote: Stuff like memory allocation in PHP is moot - ...
LOL....
Let me try to restate my position in a much more concise manner. I don't feel it's good for individuals that really want to learn how to program to do so without an understanding of how their code is affecting the machine. On the other hand, if all you're concerened about is building web sites and apps for bozos in suits so they can get their reports faster, go right on ahead don't worry about what I'm saying.
There are a number of people that I agreement with (as they've been there and I hear the logic of their rantings). Joel Spolsky, Donald Knuth, and Fabian Pascal. All very accomplished and very respected. Below is a link to a story by Joel Spolsky that really sums up my feelings on the topic.
http://www.joelonsoftware.com/articles/ ... 00319.html
Cheers,
BDKR
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
I could be wrong here but he might be talking about creating code in PHP that is not memory hungry or not throwing code at a problem that causes the memory usage to balloon needlessly.onion2k wrote:I've no idea what you've been doing for the last six years, but if was looking for a malloc function in PHP you've been wasting your time.BDKR wrote:You're kidding right? What have I been doing for the last six years?Maugrim_The_Reaper wrote: Stuff like memory allocation in PHP is moot - ...
One of the problems I have seen with many PHP packages is how the programmers create code as if they have unlimited memory resources. There was one game that loaded around 10+ different LARGE classes and modules for every single page load and the amount of memory it comsumed was 10 times more than it should have used if the programmer would have used his head in only loading what was needed when it was needed. Plus the classes had alot of junk in them that wasn't being needed or used and could have been stripped down alot.
By reducing the memory overhead you also increase execution speed in most cases. There is a form of memory allocation when programming in PHP. It's called efficient programming and not throwing code at a problem.
I was actually joking about the malloc thing .. making fun of BDKR's "I'm waaaaay more experienced than you!" comment regarding his six years experience. The assumption that you're better simply because you've been doing something longer irritates me.AKA Panama Jack wrote:I could be wrong here but he might be talking about creating code in PHP that is not memory hungry or not throwing code at a problem that causes the memory usage to balloon needlessly.onion2k wrote:I've no idea what you've been doing for the last six years, but if was looking for a malloc function in PHP you've been wasting your time.BDKR wrote: You're kidding right? What have I been doing for the last six years?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Onion, my freind. You've got me wrong here. That was a joke. Put what I said in context and you'll see that I was responding to something someone else said. That was kinda my way of saying Duh!!! LOL..... Panama understands what I'm getting at.onion2k wrote: I was actually joking about the malloc thing .. making fun of BDKR's "I'm waaaaay more experienced than you!" comment regarding his six years experience. The assumption that you're better simply because you've been doing something longer irritates me.
Sorry for misleading ya. I don't really think I'm better then everyone else when it comes to programming. The only time I was really like that was when I road raced motorcycles.
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
Chuckle I understand...onion2k wrote:I was actually joking about the malloc thing .. making fun of BDKR's "I'm waaaaay more experienced than you!" comment regarding his six years experience. The assumption that you're better simply because you've been doing something longer irritates me.
I have been programming for 26 years and there are people who will say I know nothing.