Garri

In my free time, I do programming.

October 2006 - Posts

OOP in PHP
Yeah! I know this blog was requested to record my learning in ASP.NET 2.0 and C#. But I'm currently doing OOP in PHP right now and I'm very happy on what I'm learning. Hopefully this helps to newbies like me enjoy OOP and practice it.

ok i've been reading the PHP Manual about OOP in PHP 5 but still I get confused on how will this work on me. I believe that OOP will help in a lot of ways. As of the moment I feel that it does. Everything you will see here are just self study, I hope you understand. Big Smile

I'm not sure either if my understanding is right or if im doing it correctly. The thing about separation of UI to the presentation logic?
Here's what i'm doing I'm avoiding embedding all PHP codes to my HTML codes. I'm just embedding the include one's.

e.g. portCategory.php
<?php
class portCategory {
   
    //Initialize Variable here.

    function portCategory () {
    }
   
    function setLink($value) {
       $this->LinkURL=$value;
    }

    function setThumb($value) {
       $this->ThumbURL=$value;
    }

    function setCaption($value) {
       $this->Caption=$value;
    }

    function displayCategory($value) {
       echo sprintf ('
                <div id="float">
                   <a href="%s"><img src="%s" />
                   <br />
                   <p>%s</a></p>
                </div>
       '
,$this->LinkURL, $this->ThumbURL, $this->Caption);
    }
?>


e.g. (Here's what I emebedded along with the HTML Code)
<?php
include ('portCategory.php'); // This contain my Class portCategory. 
include ('connectionDB.php'); //My DB Connection.
           

//Query all data needed from the database.
$myQuery = "SELECT * FROM myTable"
$resultMyQuery = mysql_query($myQuery);

//create While
while ($data = mysql_fetch_array($
resultMyQuery, MYSQL_BOTH) {
    $portCategory = new portCategory;
    $portCategory->setThumb($data['ImageURL']);
    $portCategory->setCaption($data['Caption']);
    $portcategory->setLink($data['LinkURL']);
    $portCategory->displayPortCategory();
}
?>

Posted: 10-18-2006 11:25 AM by Garri | with 3 comment(s)
Filed under:
It's been a while.

Hehehe It's been ages.

I have been uber busy, OK about my learning.

I'm not quite familiar with OOP (Object-Oriented Programming) so I've ask people if they know a good book available locally, here in the Philippines. Lamia a member here in DevPinoy suggested the book OOP Demystified.

After reading the two chapters, I have to say it's worth it. So for those like me who unfortunately did not have the chance to learn OOP I can recommend this book to you.

Aside from that, Im currently doing my OOP in PHP 5. Practicing and hoping one day I could implement this kind of programming to my projects.