sniperscope Posted January 28, 2011 Share Posted January 28, 2011 Hello First of all i am very weak about OOP and classes in php. I am learning now but i stuck with very silly problem. My codes are below. <?php class myTestClass { function __construct() { $this->OldName("This is Old Name"); } function OldName($VeryOld) { if($VeryOld == "This is Old Name") $this->NewName(); else $VeryOld = "Something Wrong"; return $VeryOld; } function NewName() { echo "This is Brand New Name"; } } $i = new myTestClass(); ?> if i send value to OldName "This is Old Name" then codes works fine. But if i send "This is Old Nameeee" then does not appear anything. what i want to do is print "Something Wrong" text if i enter different value. I have no idea what return do and how it do? How to retrieve/print "Something Wrong"? i can do that with echo but i want to transfer result of return to another function. Really appreciate for any help/idea. Quote Link to comment https://forums.phpfreaks.com/topic/225934-about-return/ Share on other sites More sharing options...
trq Posted January 28, 2011 Share Posted January 28, 2011 Firstly, your logic itself doesn't really make sense. It says, (calling OldName()) if the username provided is the same as the current name, call a function that displays 'this is a brand new name' Can you see any sense it that logic? Quote Link to comment https://forums.phpfreaks.com/topic/225934-about-return/#findComment-1166422 Share on other sites More sharing options...
sniperscope Posted January 28, 2011 Author Share Posted January 28, 2011 First of all, i am very very very beginner of class. All i want to do is autorun class when it created. Then Skip to OldName and parse same variable. Check that variable, if it is true then go to NewName else return error message. Like i said i am new about OOP. I can do what i want with functions but i want to learn class. Quote Link to comment https://forums.phpfreaks.com/topic/225934-about-return/#findComment-1166429 Share on other sites More sharing options...
trq Posted January 28, 2011 Share Posted January 28, 2011 The logic you have described has nothing to do with whether or not its done inside a class or not, besides, this really is a bad example of how classes work. Generally, a class wouldn't automtically execute its functionality when instantiated. Quote Link to comment https://forums.phpfreaks.com/topic/225934-about-return/#findComment-1166435 Share on other sites More sharing options...
sniperscope Posted January 28, 2011 Author Share Posted January 28, 2011 Dear Thorpe Thanks for your reply. so, do have any suggestion(s) to learn classes painless? I am reading class tutorails on phpfreaks but frankly i did not get the idea exactly. Because there is still a lot of question marks in my mind. Quote Link to comment https://forums.phpfreaks.com/topic/225934-about-return/#findComment-1166438 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.