Jump to content

about: return


sniperscope

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/225934-about-return/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/225934-about-return/#findComment-1166429
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.