ignore this post

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
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

ignore this post

Post by scarface222 »

removed
Last edited by scarface222 on Mon Feb 08, 2010 5:38 pm, edited 2 times in total.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: For those of you with messy code...

Post by Eran »

I would suggest against using this article as direct reference, as it uses PHP4 conventions which have been defunct for several years now (not surprisingly, the article is from 2002)
limitdesigns
Forum Commoner
Posts: 25
Joined: Sat Feb 06, 2010 9:05 pm

Re: For those of you with messy code...

Post by limitdesigns »

Object-oriented programming isn't so much for performance as it is for organization and convenience. It's much easier to use OOP in large applications than it is to use only public functions.
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: ignore this post

Post by scarface222 »

Thanks for your comments guys, especially pytrin as usual I will look into a later standard of oop. Well at least I learned not to use it haha. When you say old conventions pytrin, do you mean php tags like this <? ?> and such? Old syntax?
User avatar
a.heresey
Forum Commoner
Posts: 59
Joined: Wed Dec 13, 2006 7:31 pm
Location: Chesapeake, VA, US

Re: ignore this post

Post by a.heresey »

For starters, you name your constructors like this now:

Code: Select all

 
class Puppy{
 
public var $cute;
public var $good;
 
__construct($cuteness, $goodness){
$this->cute = $cuteness;
$this->good = $goodness;
 
}
 
and you can use the mysqli (my sql improved) object for connecting to the database

Code: Select all

 
$mysqli = new mysqli('localhost','username','password','database');
 
if (mysqli_connect_error()){
die("Connection Error (".mysqli_connect_errno().") ".mysqli_connect_error());
}
 
and you can designate properties and methods as private, protected, and public

and getters and setters are kinda controversial.

Other than that I think it was a really easy to understand tutorial.

This is my current fav OOP tutorial:
http://www.devshed.com/c/a/PHP/ObjectOr ... -Patterns/

Please post any good resources you find on OOP, as I am new to OOP too!
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: ignore this post

Post by Eran »

@heresey You shouldn't use 'var' with visibility keywords (public,protected,private), the latter are meant to replace the former.
@scarface, you can read all about PHP "new" OOP model in PHP5 in the manual -
http://php.net/manual/en/language.oop5.php
Some main changes:
- constructors / destructors
- method and member visibility
- magical methods (__get,__set, etc)
- scope resolution operator (::)
- much more
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: ignore this post

Post by scarface222 »

alright thanks guys, appreciate the tips
Post Reply