Req #63268 [Com]: Scalar Casting
| From: | klaussantana at gmail dot com | Date: | Fri, 12 Oct 2012 21:20:23 +0000 |
| Subject: | Req #63268 [Com]: Scalar Casting | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-174058@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63268&edit=1
ID: 63268
Comment by: klaussantana at gmail dot com
Reported by: klaussantana at gmail dot com
Summary: Scalar Casting
Status: Open
Type: Feature/Change Request
Package: Unknown/Other Function
Operating System: Any
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Note that it'll be automatically chainable because the result of ->toLower() is a
string and it will cast as an object...
And you'll can also do something like this:
echo 'My String'->toLower();
Just suggestions.. comment.
Previous Comments:
------------------------------------------------------------------------
[2012-10-12 21:16:36] klaussantana at gmail dot com
Description:
------------
It would be nice if we can control the casting behavior of any type to another.
Like a function like this:
register_casting_behavior( $from, $to, $callback_function );
So when you do this:
register_casting_behavior( 'int', 'bool', 'int2bool' );
$X = (bool) 1;
It will call int2bool( 1 ) and so...
Then....
Test script:
---------------
register_casting_behavior( 'string', 'object', array( 'String',
'__construct' ) );
class String
{
protected $value = null;
public function __construct( $String )
{
$this->value = $String;
return $this;
}
public function toLower()
{
return strtolower($this->value);
}
public function underline()
{
return "<span style='text-decoration:
underline;'>{$this->value}</span>";
}
}
$S = 'My String';
echo $S->toLower()->underline();
// will output: <span style='text-decoration: underline;'>my string</span>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63268&edit=1