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 Link to comment https://forums.phpfreaks.com/topic/47647-object-oriented-programming-help/ 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 Link to comment https://forums.phpfreaks.com/topic/47647-object-oriented-programming-help/#findComment-232697 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. Link to comment https://forums.phpfreaks.com/topic/47647-object-oriented-programming-help/#findComment-232708 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 Link to comment https://forums.phpfreaks.com/topic/47647-object-oriented-programming-help/#findComment-232766 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? Link to comment https://forums.phpfreaks.com/topic/47647-object-oriented-programming-help/#findComment-232776 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. Link to comment https://forums.phpfreaks.com/topic/47647-object-oriented-programming-help/#findComment-232777 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.