Req #62783 [Opn]: Request of using methods for core types.
Edit report at https://bugs.php.net/bug.php?id=62783&edit=1
ID: 62783
Updated by: laruence@php.net
Reported by: hinikato at mail dot ru
Summary: Request of using methods for core types.
Status: Open
Type: Feature/Change Request
Package: Class/Object related
PHP Version: 5.4.6RC1
Block user comment: N
Private report: N
New Comment:
you can already do it with a wrapper of string now:
<?php
class Strings {
private $str = NULL;
function __construct($str) {
$this->str = $str;
}
function __call($method, $params) {
return new self($method($this->str));
}
function __toString() {
return $this->str;
}
}
echo (new Strings("Hello, World"))->strtolower()->ucfirst();
Previous Comments:
------------------------------------------------------------------------
[2012-08-09 00:50:39] hinikato at mail dot ru
Removed the non-relevant field for the issue description.
------------------------------------------------------------------------
[2012-08-09 00:38:00] hinikato at mail dot ru
Description:
------------
I propose to introduce new methods for the core PHP types like arrays, strings, floats etc? For
example it would be super cool to write something like this:
[1, 2, 3]->sort()
"Hello, World"->lowercase()->ucfirst() etc.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62783&edit=1
Thread (8 messages)