This is a discussion on PHP Config option so $this isn't required within class methods? within the PHP General forums, part of the PHP Programming Forums category; Greetings, Is there a configuration option for any PHP version that would allow for usages of class methods from within ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Greetings,
Is there a configuration option for any PHP version that would allow for usages of class methods from within a class, without needing to use "$this->"? Using it isn't a problem. I'm asking because I just recently started using an IDE which doesn't seem to require this, and makes me wonder if it's possible to do this. An example of what I mean: <?php class test { function a() { b(); //instead of $this->b(); } function b() { echo "b called\r\n"; } } $test = new test(); $test->a(); ?> Thanks! |
|
|||
|
Michael Martinek wrote:
> Greetings, > > Is there a configuration option for any PHP version that would allow > for usages of class methods from within a class, without needing to > use "$this->"? > > Using it isn't a problem. I'm asking because I just recently started > using an IDE which doesn't seem to require this, and makes me wonder > if it's possible to do this. > > An example of what I mean: > > <?php > class test { > function a() { > b(); //instead of $this->b(); > } > > function b() { echo "b called\r\n"; } > } > > $test = new test(); > $test->a(); > > ?> > > Thanks! No, and you would not want that. What if you had a function named b outside the class? It wouldnt know which one to use! This is 'scope'. you can do final class log { public function echo($data) { file_put_contents('echo.log',file_get_contents('ec ho.log')."\n{$data}"); echo $data; } } log::echo('<html>'); log::echo('<body>'); log::echo('hello'); log::echo('</body>'); log::echo('</html>'); would echo just like echo.. but add logging feature to it, without needing to come up with a new function name. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|