Skip to main content
added 74 characters in body
Source Link
Sasha Chedygov
  • 131.6k
  • 27
  • 107
  • 117

Okay, so let's remove the need for writing $this everywhere. Take a look at this situation:

class Foo { public function setBar($value) { $bar = $value; } } $foo = new Foo(); $foo->setBar('some value'); 

Is $bar a local variable or a member of $foo?

There has to be some differentiation. They could have allowed declaration of local variables with the var keyword, but that would not have been backwards-compatible and would have been very confusing to people upgrading from older versions of PHP.

AtSame thing applies to self::. How does the end ofinterpreter know whether the day, though,function you wanted to call is it really that big of a dealglobal or specific to the class?

Okay, so let's remove the need for writing $this everywhere. Take a look at this situation:

class Foo { public function setBar($value) { $bar = $value; } } $foo = new Foo(); $foo->setBar('some value'); 

Is $bar a local variable or a member of $foo?

There has to be some differentiation. They could have allowed declaration of local variables with the var keyword, but that would not have been backwards-compatible and would have been very confusing to people upgrading from older versions of PHP.

At the end of the day, though, is it really that big of a deal?

Okay, so let's remove the need for writing $this everywhere. Take a look at this situation:

class Foo { public function setBar($value) { $bar = $value; } } $foo = new Foo(); $foo->setBar('some value'); 

Is $bar a local variable or a member of $foo?

There has to be some differentiation. They could have allowed declaration of local variables with the var keyword, but that would not have been backwards-compatible and would have been very confusing to people upgrading from older versions of PHP.

Same thing applies to self::. How does the interpreter know whether the function you wanted to call is global or specific to the class?

Source Link
Sasha Chedygov
  • 131.6k
  • 27
  • 107
  • 117

Okay, so let's remove the need for writing $this everywhere. Take a look at this situation:

class Foo { public function setBar($value) { $bar = $value; } } $foo = new Foo(); $foo->setBar('some value'); 

Is $bar a local variable or a member of $foo?

There has to be some differentiation. They could have allowed declaration of local variables with the var keyword, but that would not have been backwards-compatible and would have been very confusing to people upgrading from older versions of PHP.

At the end of the day, though, is it really that big of a deal?