PHP Config option so $this isn't required within class methods?

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-12-2008
Michael Martinek
 
Posts: n/a
Default PHP Config option so $this isn't required within class methods?

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!
Reply With Quote
  #2 (permalink)  
Old 01-13-2008
Daniel
 
Posts: n/a
Default Re: PHP Config option so $this isn't required within class methods?

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.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:58 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0