dannyman1234 Posted June 30, 2009 Report Share Posted June 30, 2009 (edited) Hi im a beginner in OOP php5 and I hope someone can help. I made a class House class House { public $AI; private $MAP; public function getAI($photo_AI) { return $this->AI; } public function getMAP() { } } THen in index.php require 'phpclasses/class_lib.php'; $house = new House(); echo $house->get_AI($_GET['photo_AI']); link: http://localhost/composeyourhouse/site/index.php?photo_AI=1.jpg The thing is that $house->get_AI is empty. What am I doing wrong and how can I make effective use of OOP in this case, because I can do echo $_GET['photo_AI']; which gives the same result. Thanks Edited June 30, 2009 by dannyman1234 Quote Link to comment Share on other sites More sharing options...
BeeDev Posted July 1, 2009 Report Share Posted July 1, 2009 You have to make another function called setAI which "sets" a value to that newly created House object. getAI should be only GETting a value, and not SETting one. public function setAI($photo_AI) { $this->AI=$photo_AI; return true; } and you getAI function shouldn't be taking $photo_AI parameter because it won't need it. Your getAI function should look like this public function getAI() { return $this->AI; } you may want to make a "constructor" function, which automatically runs when you create a new object. Read about it here: http://www.killersites.com/forums/topic/1732/new-oop-php-question/ 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.
Note: Your post will require moderator approval before it will be visible.