darknessmdk Posted April 18, 2007 Share Posted April 18, 2007 So I've deceided to learn Object Oriented Programming and i looked the tutorial on this site and found it very confusing. Does anyone know of a example that someone could show me or another tutorial. A practical example would be great. Thanks Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted April 18, 2007 Share Posted April 18, 2007 Heres a good series: http://www.tutorialized.com/tutorials/PHP/OOP/1 Quote Link to comment Share on other sites More sharing options...
Glyde Posted April 18, 2007 Share Posted April 18, 2007 Here is a basic sample script you can upload and run: <?php class myClass { var $className = "myClass"; var $x = 1; function printClass() { print $this->className; } } class testClass extends myClass { var $className = "testClass"; var $y = 2; function myFunction() { $sum = $this->x + $this->y; print "x + y = " . $sum; } } $m = new myClass(); $t = new testClass(); $m->printClass(); // Should output 'myClass' $t->printClass(); // Should output 'testClass' $t->myFunction() // Should output x + y = 3; ?> That's sort of a general tutorial on how classes work (using the $this-> syntax), and how extending classes works. OOP is really simple in PHP, and when you look at it in the simplest form, it's just a collection of functions and variables which may or may not have a relation. Quote Link to comment Share on other sites More sharing options...
darknessmdk Posted April 19, 2007 Author Share Posted April 19, 2007 awesome! thanks to the both of you Quote Link to comment Share on other sites More sharing options...
lifeson2112 Posted April 19, 2007 Share Posted April 19, 2007 I was looking at the code and noticed the $this variables pointing to the object. Does PHP reserve these variables? Quote Link to comment Share on other sites More sharing options...
Glyde Posted April 19, 2007 Share Posted April 19, 2007 Yes, $this is a PHP reserved variable. Only in a class though. I believe it is valid to be used outside of a class. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.