Forum Moderators: coopster

Message Too Old, No Replies

OO resources for php

Anyone have any useful resources

         

ironik

5:17 am on Mar 29, 2005 (gmt 0)

10+ Year Member



I'm starting to delve a little more into Object Oriented programming for PHP and I'm struggling to find decent resources. Basically I'm starting to restructure some of my existing functional code into modular object oriented code (loosely based on the MVC approach).

If anyone has any links to free resources or something that'll help me get my head around OO code for PHP, particularly using multiple cooperating classes I would be eternally grateful!

(also love to hear from anyone who's gone through the same learning curve. I've only ever used generic classes that have no interaction and my knowledge is letting me down a little!)

Thanks in advance :)

[edited by: ironik at 5:19 am (utc) on Mar. 29, 2005]

jamie

5:19 am on Mar 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



[phppatterns.com...] is a good resource

ironik

5:36 am on Mar 29, 2005 (gmt 0)

10+ Year Member



Great resource! There's quite a few links to articles to have a read through. I think I've read some of Harry's stuff on sitepoint... one smart cookie.

wrightee

7:03 am on Mar 29, 2005 (gmt 0)

10+ Year Member



www.phpclasses.org - not tutorials, but lots of classes to learn from

anshul

7:23 am on Mar 29, 2005 (gmt 0)

10+ Year Member



Two examples I just wrote may initiate you :)

<?php
class Student {
var $name, $m1, $m2, $m3, $m4, $m5;
function setVal($value, $m1, $m2, $m3, $m4, $m5) {
$this->name=$value;
$this->m1=$m1;
$this->m2=$m2;
$this->m3=$m3;
$this->m4=$m4;
$this->m5=$m5;
}
function printName() {
echo $this->name;
echo "<br>";
}
function calAverage() {
echo ($this->m1+$this->m2+$this->m3+$this->m4+$this->m5)/5;
echo "<br><br>";
}
}

$s1=new Student;
$s1->setVal("Mohit", 52, 36, 70, 63, 45);
$s1->printName();
$s1->calAverage();

$s2=new Student;
$s2->setVal("Rohit", 51, 36, 67, 43, 35);
$s2->printName();
$s2->calAverage();

$s3=new Student;
$s3->setVal("Pankaj", 61, 56, 76, 53, 55);
$s3->printName();
$s3->calAverage();

?>

<?php
class Connection {
var $host, $user, $password;

function initialize($h, $u, $p) {
$this->host=$h;
$this->user=$u;
$this->password=$p;
}

function connect() {
mysql_connect($this->host, $this->user, $this->password);
echo "Successfully connected to MySQL database Server.";
}
}

$conn=new Connection();
$conn->initialize('localhost', 'admin', 'admin');
$conn->connect();
?>

ironik

9:56 pm on Mar 29, 2005 (gmt 0)

10+ Year Member



Thanks wrightee, anshul

I'm subscribed to phpclasses already, great site to find classes without having to 'reinvent the wheel'.

Last night I tested out my code based on my understanding of the MVC pattern. To my surprise after only 1/2 hour of debugging it was working pretty smoothly, I have about 10 classes that are working harmoniously together... there will probably be a few more when I manage to finish it.

Thanks again