What is wrong with this code:

It is for static page, dynamic page, website, SEO, performance and other web development discussion
ramverma
Posts: 435
Joined: Sat Aug 23, 2014 5:34 pm
Contact:

What is wrong with this code:

Postby ramverma » Mon Oct 19, 2015 6:16 am

What is wrong with this code:
class SomeClass
{
protected $_someMember;

public function __construct()
{
$this->_someMember = 1;
}

public static function getSomethingStatic()
{
return $this->_someMember * 5; // here's the catch
}
}


jeff2345
Posts: 49
Joined: Tue May 05, 2015 7:09 pm
Contact:

Re: What is wrong with this code:

Postby jeff2345 » Tue Oct 20, 2015 6:36 am

Static methods don't have access to $this, because static methods can be executed without instantiating a class.


Return to “PHP, HTML, MYSQL and Web Hosting”

Who is online

Users browsing this forum: No registered users and 1 guest