Edit report at https://bugs.php.net/bug.php?id=62860&edit=1

 ID:                 62860
 Updated by:         re...@php.net
 Reported by:        michaelduff2 at yahoo dot com
 Summary:            Moar magic methods! __constructStatic(),
                     __getStatic(), __setStatic(), __get
-Status:             Open
+Status:             Duplicate
 Type:               Feature/Change Request
 Package:            *General Issues
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

Duplicate to https://bugs.php.net/bug.php?id=45002 closed.


Previous Comments:
------------------------------------------------------------------------
[2012-09-05 15:12:01] matthew dot bonner at gmail dot com

Sorry in my last example there was a typo, and what I meant was:
I would like to add that being magic methods, it would be nice if they could do 
a little more magic, ie:

class Classy {
  public static $foo = 'foo';
  public $bar = 'bar';

  public static function __get ($propertyName) {
    return self::$propertyName;
  }

  public function __get ($propertyName) {
    return $this->$propertyName;
  }
}

echo Classy::$foo; // outputs "foo"
$classy = new Classy;
echo $classy->bar; // outputs "bar"

------------------------------------------------------------------------
[2012-09-05 15:10:36] matthew dot bonner at gmail dot com

I would like to add that being magic methods, it would be nice if they could do 
a little more magic, ie:

class Classy {
  public static $foo = 'foo';
  public $bar = 'bar';

  public static function __get ($propertyName) {
    return $this->$propertyName;
  }

  public function __get ($propertyName) {
    return self::$propertyName;
  }
}

echo Classy::$foo; // outputs "foo"
$classy = new Classy;
echo $classy->bar; // outputs "bar"

------------------------------------------------------------------------
[2012-09-05 15:06:06] matthew dot bonner at gmail dot com

The additional magic methods with static support have been requested over and 
over for well over 5 years now. Is PHP a dying language because the developers 
don't have the time to provide essential functionality?

There are so many hacks going about now to try and provide essential 
functionality and there is so much messy code all over the place to support 
what should be part of PHP 5 as standard.

Sorry for my raving and ranting but the reputation of PHP is being severely 
damaged by not providing the essentials.

.NET has static accessor and mutator support, Java does too. All the big 
languages do apart from PHP.

class PLEASE_SUPPORT_AT_A_MINIMUM {
  public static function __construct () {}
  public static function __set ($propertyName, $propertyValue) {}
  public static function __get ($propertyName) {}

  public function setConstDynamically () {
    const Foo = 'foo';
    echo self::Foo;
  }
}

Otherwise I will fork PHP and provide this essential functionality myself which 
will ultimately result in the death of the original PHP.

------------------------------------------------------------------------
[2012-08-18 20:03:22] michaelduff2 at yahoo dot com

Description:
------------
__constructStatic() - executed automatically on class definition

__getStatic() - executed when ClassName::$inaccessible_property is fetched

__setStatic() - executed when ClassName::$inaccessible_property is modified


The particular use case I have for this is self-loading configuration registry 
singletons:

<?php7

namespace Company;

class Config
{
    protected static $settings;

    function __constructStatic($property)
    {
        static::$settings = parse_ini_file('config.ini');
    }

    function __getStatic($property)
    {
        return static::$settings[$property];
    }
}

echo Config::$DB_USER;

?>

Currently, I accomplish this with __callStatic() which needs the extra 
open-close parenthesis.  Ideally, we could get rid of the '$' too, but that 
would need some __getConst() magic, which is just madness.



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=62860&edit=1

Reply via email to