rfc:unset_bool
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:unset_bool [2013/03/06 22:34] – + microbenchmark bwoebi | rfc:unset_bool [2018/06/18 10:14] (current) – This RFC appears to be inactive cmb | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: unset(): return bool if the variable has existed ====== | ====== PHP RFC: unset(): return bool if the variable has existed ====== | ||
- | * Version: 0.53 | + | * Version: 0.61 |
* Date: 2013-03-06 | * Date: 2013-03-06 | ||
* Author: Bob Weinand, bobwei9@hotmail.com | * Author: Bob Weinand, bobwei9@hotmail.com | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
* Implementation: | * Implementation: | ||
Line 17: | Line 17: | ||
Change unset()' | Change unset()' | ||
* return true if deletion was successful | * return true if deletion was successful | ||
- | * return false if deletion failed | + | * return false if deletion failed |
The feature could be useful in if's like: | The feature could be useful in if's like: | ||
Line 75: | Line 75: | ||
var_dump(unset($class-> | var_dump(unset($class-> | ||
</ | </ | ||
+ | |||
+ | ===== Use case ===== | ||
+ | <code php> | ||
+ | class User { | ||
+ | private $data = []; | ||
+ | |||
+ | // here a __set and a __get function for $data | ||
+ | |||
+ | public function __unset ($key) { | ||
+ | switch ($key) { | ||
+ | case " | ||
+ | return false; | ||
+ | default: | ||
+ | return unset($this-> | ||
+ | } | ||
+ | } | ||
+ | |||
+ | class UserManager { | ||
+ | private $Users = []; | ||
+ | |||
+ | public function __construct($data) { | ||
+ | // some code to initialize the $this-> | ||
+ | } | ||
+ | |||
+ | public function reset($userId, | ||
+ | if (!unset($this-> | ||
+ | throw new Exception(" | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | $manager = new UserManager($data); | ||
+ | |||
+ | $manager-> | ||
+ | </ | ||
+ | |||
+ | This genre of code could be also in Frameworks to indicate to a coder that the variable can be accessed, but not deleted. | ||
===== Implementation Details === | ===== Implementation Details === | ||
Line 121: | Line 158: | ||
* Version 0.52: echo may be also considered as a function... | * Version 0.52: echo may be also considered as a function... | ||
* Version 0.53: Added microbenchmark | * Version 0.53: Added microbenchmark | ||
+ | * Version 0.6: Added example real world use case | ||
+ | * Version 0.61: Little clarification about failures |
rfc/unset_bool.1362609264.txt.gz · Last modified: 2017/09/22 13:28 (external edit)