One of the things I have always really liked about php is that variable
scope is always very explicit. You always know where a variable is
coming from and you don't ever have to worry about where or not you are
working with a variable in the right scope.

If something like this were to ever creep into php I would be very sad.

----------
Mike Lively (ds- on irc.efnet.org)


On Fri, 2006-02-24 at 14:05 +0000, [EMAIL PROTECTED] wrote:
> Hi all.
> 
> I'm using php 5.1.2 compiled from source, with Apache 2.2.0 
> and MySQL 5.0.18 on SuSE Linux 9.2 pro.
> 
> I really do not see the need to keep telling php I'm 
> refering to the properties and method of the class I'm 
> already in, when php 5 should be able to deduce this from 
> the context of the class I'm coding in.
> 
> I was wondering if it would be possible in future versions 
> of php to provide a PHP_INI_CLASS constant and a 
> this.use_implicit TRUE|FALSE option please, valid only 
> within a class's definition? I guess it could be moved to 
> php.ini later, if it became popular, and was required there.
> 
> This would allow a programmer to set the default value of 
> whether to use $this-> as a prefix to class properties and 
> methods, or not. (Similar to the way php 5.1.2 handles 
> methods without a visibility declaration - i.e. they default 
> to public)
> 
> This option to select default implicit referencing could 
> also apply to inherited properties and methods.
> 
> This would save ALOT of repetitive typing, and make the code 
> alot more concise. This would be similar to & being made 
> implicit when passing object references to method calls.
> 
> this.use_implicit could default to FALSE, so it would not 
> interfere with current code compatibility.
> 
> Developers could then choose to enable this.use_implicit 
> on a class by class basis. This would allow a developer to 
> do a gradual upgrade of their classes, without breaking any 
> code.
> 
> The only problem I can see, is that the parameters passed to 
> the __construct() function would have to use different names 
> to avoid any ambiguity conflicts  - see example below.
> 
> As the parameters are only usually passed into a class once, 
> when the object is instantiated, this would cut down on a 
> lot of coding once the parameters are inside the class.
> 
> So, instead of coding something like:
> 
> (From chapter 19 example 25 of the manual)
> 
> <?php
> 
> class Connection {
>     protected $link;
>     private $server, $username, $password, $db;
>     
>     public function __construct($server, $username, $password, $db)
>     {
>         $this->server = $server;
>         $this->username = $username;
>         $this->password = $password;
>         $this->db = $db;
>         $this->connect();
>     }
>     
>     private function connect()
>     {
>         $this->link = mysql_connect($this->server, $this->username, 
> $this->password);
>         mysql_select_db($this->db, $this->link);
>     }
>     
>     public function __sleep()
>     {
>         mysql_close($this->link);
>     }
>     
>     public function __wakeup()
>     {
>         $this->connect();
>     }
> }
> ?> 
> 
> 
> I was thinking of something more like this:
> 
> <?php
> 
> class Connection {
>     
>     // use $this-> implicitly within this class only
>     ini_set('this.use_implicit', ON);
> 
>     protected $link;
>     private $server, $username, $password, $db;
>     
>     public function __construct($server_p, $username_p, $password_p, $db_p)
>     {
>         $server    = $server_p;
>         $username  = $username_p;
>         $password  = $password_p;
>         $db        = $db_p;
>         connect();
>     }
>     
>     private function connect()
>     {
>         $link = mysql_connect($server, $username, $password);
>         mysql_select_db($db, $link);
>     }
>     
>     public function __sleep()
>     {
>         mysql_close($link);
>     }
>     
>     public function __wakeup()
>     {
>         connect();
>     }
> }
> 
> ?> 
> 
> 
> Any comments or suggestions would be welcomed.
> 
> Keith Roberts
> 
> In theory, theory and practice are the same;
> In practice they are not. 
> 

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to