Jump to content

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

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.