Jump to content

What's the difference between 2 classes?


Recommended Posts

Hi,

 

There are two classes; a and b.

 

class a

{

private $a;

public function method_a($_a)

{

return $a = $_a;

}

}

$var = new a();

echo $var->method_a("Some value");

 

class b

{

private $b;

public function method_b($_b)

{

return $this->b = $_b; }

}

$var = new b();

echo $var->method_b("Some value");

 

What is the real difference between two classes?

 

Thanks

Link to comment
Share on other sites

Nothing really, there both incorrectly returning a bool.

 

he uses = that doesn't return a bool rather the assigned value (in this case a string). See, VB is bad for your health.

 

What is the real difference between two classes?

 

In the second you assign the value to an internal class variable. Both return your input "Some value".

Link to comment
Share on other sites

he uses = that doesn't return a bool rather the assigned value (in this case a string). See, VB is bad for your health.

 

Oh, indeed it does. I would have assumed it would have returned a bool based on whether or not the assignment worked or not.

Link to comment
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.