Any Good PHP5 OOP Resources?

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Fri Nov 03, 2006 11:31 am    Post subject: Any Good PHP5 OOP Resources? Reply with quote

I noticed that PHP5 is starting to move to the Object Oriented side of things and
I want to prepare FileLimit 3.0 for PHP6 just incase functions become Classes! It
really gets on my nerves when they change stuff all the time.

I've been looking at the changes in PHP 5.2.0 for the ZIP extension, and get
this! It uses a Class to write a zip archive instead of a set of functions, which is
giberish to me. So is there any good resources on PHP5's OOP?

Thanks for any help on this. I plan to take a long break on the FileLimit 3.0
Development and wait untill I know more on Objects.

I searched all over Google and found nothing!
Back to top View user's profile Send private message Visit poster's website
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Fri Nov 03, 2006 1:37 pm    Post subject: Re: Any Good PHP5 OOP Resources? Reply with quote

TRUSTAbyss,

From your question, it seems that you're looking for information to use already available classes. This is easier than having to understand all the theory behind OOP and its implementation in PHP5.

For the Zip extension in PHP, the examples provided in http://www.php.net/zip are sufficent to understand how to use it (without even knowing what OOP is all about). Just create a new Zip object:

Code:
$zip = new ZipArchive();


and perform operations on $zip. Instead of using the syntax function_name($zip, arg1, arg2, ....), consider that you have to use now $zip->function_name(arg1, arg2, ....) instead.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Fri Nov 03, 2006 9:35 pm    Post subject: Reply with quote

Actually I'm wondering how to write my own so my FileLimit 3.0 code becomes
stable through out all PHP versions.

The PHP manual does not explain OOP that well. I want a baby step process
that works my way up the latter untill I know it.

This is all I know so far. How is any of this stuff useful than regular functions?

Code:
<?php
class HelloWorld {

    public $hello = "Hello, World!";
}

$msg = new HelloWorld();

echo $msg->hello;
?>
Back to top View user's profile Send private message Visit poster's website
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Sat Nov 04, 2006 8:08 am    Post subject: Reply with quote

PHP.net's docs are probably the best you'll find.
Personally I wouldn't use any PHP5 specific stuff though, since a lot of people won't be upgrading their PHP installations any time soon.

Classes have their uses, php.net's main example is a good example of them.
The best example I can be bothered to write at 6AM is:
Code:
class db {
  var $link;
  function db($hostname, $username, $password, $database) {
    if (!$this->link = @mysql_connect($hostname, $username, $password))
      return false;
    mysql_select_db($database, $this->link);
    return true;
  }
  function query($query) {
    return mysql_query($query, $this->link);
  }
}
$db1 = new db("server1.example.com", "dave", "asdf", "mydb");
$db2 = new db("server2.example.com", "dave", "asdf", "otherdb");
$db1->query("UPDATE `users` SET `stuff` = stuff+1");
$db2->query("SELECT `age` FROM `users` WHERE `username` = 'dave'");
/*
 * As opposed to something like: mysql_query("SELECT ...", $resource).
 * Admittedly there are better uses than this, but it's an easy enough example.
 */


Note: If you didn't get it, it's just to make handling multiple connections slightly easier.
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Sun Nov 05, 2006 7:58 am    Post subject: Reply with quote

Hello MonkeyNation,

I've been experimenting with my own Objects, which I've learned from the VTC
PHP lessons (Teaching PHP from Movies). I've went through the whole chapter
and learned alot about the Object Oriented features.

One of the benefits from using it, is that it allows you to recycle code, but unlike
a standard function, an Object has multiple functions within it! This makes it very
clean code, without having a bunch of functions to do the same.

I now understand the concept behind Objects. Thank You.
Back to top View user's profile Send private message Visit poster's website
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Sun Nov 05, 2006 3:03 pm    Post subject: Reply with quote

TRUSTAbyss,

The real advantage of OOP is class inheritance: http://en.wikipedia.org/wiki/Inheritance_(computer_science) .
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Mon Nov 06, 2006 2:43 am    Post subject: Reply with quote

Inheritance is also very useful. I like how you're able to extend the methods
and attributes from one Object to the other.
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group