note 109405 added to language.oop5.typehinting

From: Date: Sat, 14 Jul 2012 09:07:29 +0000
Subject: note 109405 added to language.oop5.typehinting
Groups: php.notes 
Request: Send a blank email to php-notes+get-189135@lists.php.net to get a copy of this message
my scalar type hinting solution (example): <?php class Scalar { /** * * @var mixed */ private $value; /** * * @param mixed $v */ public function __construct($v) { $this->value = $v; } /** * * @return string */ public function __toString() { $v = strval($this->value); return $v; } /** * * @return bool */ public function toBool() { $v = (bool) $this->value; return $v; } /** * * @return float */ public function toFloat() { $v = floatval($this->value); return $v; } /** * * @return int */ public function toInt() { $v = intval($this->value); return $v; } /** * * @return string */ public function toString() { $v = strval($this->value); return $v; } } class String extends Scalar { /** * * @param string $v */ public function __construct($v) { if (is_string($v)) { parent::__construct($v); } else { throw new InvalidArgumentException(); } } /** * * @param mixed $v * @return String */ public static function parse($v) { $v = strval($v); return new String($v); } } /** * * @param string $s */ function myFunction($s) { new String($s); // now $s must be a string to continue ... } Code could be found here: https://code.google.com/p/myquicknet/source/browse/src/php_class/com/googlecode/myquicknet/scalar/ ---- Server IP: 203.169.204.174 Probable Submitter: 124.244.171.10 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.typehinting.php Edit -- https://master.php.net/note/edit/109405 Del: integrated -- https://master.php.net/note/delete/109405/integrated Del: useless -- https://master.php.net/note/delete/109405/useless Del: bad code -- https://master.php.net/note/delete/109405/bad+code Del: spam -- https://master.php.net/note/delete/109405/spam Del: non-english -- https://master.php.net/note/delete/109405/non-english Del: in docs -- https://master.php.net/note/delete/109405/in+docs Del: other reasons-- https://master.php.net/note/delete/109405 Reject -- https://master.php.net/note/reject/109405 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#189135) next »