Jump to content

Is it safe to say...


ballhogjoni

Recommended Posts

class myClass {
public $i;

public function __construct() {
  $this->i = 5;
} 

public function i() {
  // method code
  return 2; 
}
}

$x = new myClass();
// will set $y to 5
$y = $x->i;
// will set $y to 2
$y = $x->i();

 

See the differences above. The first is a ref to a class variable.

The second is a class method

Link to comment
Share on other sites

Actually

$thisObject->doSomething();

 

I think methods have to be called with parentheses even if there are no required parameters... haven't they?

Yes, they do.

 

yes. my bad.

 

class SomeObject {
     function doSomething () {
          echo "hello world!";
     }
}

$thisObject = new SomeObject();
$thisObject->doSomething();

 

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.