This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| abstract class Enum | |
| { | |
| private $scalar; | |
| function __construct($value) | |
| { | |
| $ref = new ReflectionObject($this); | |
| $consts = $ref->getConstants(); | |
| if (! in_array($value, $consts, true)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Hoge { | |
| static function foo() { | |
| echo 'Hoge::foo'; | |
| } | |
| } | |
| $hoge = new Hoge; | |
| $hoge->foo(); //一切エラーは発生しない |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| hogehoge(); | |
| fugafuga(); | |
| //*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // intだけに制限する | |
| class IntArray extends ArrayObject | |
| { | |
| function offsetSet($offset, $value) { | |
| if (is_int($value)) { | |
| return parent::offsetSet($offset, $value); | |
| } | |
| throw new InvalidArgumentException; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Klass(){} | |
| Klass.prototype.foo = 'foo'; | |
| var o = new Klass; | |
| console.log(o.constructor.name); //Klass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class A { | |
| } | |
| $classname = 'A'; | |
| $a = new A; //Aオブジェクト1 | |
| $b = new $classname; //Aオブジェクト2 | |
| $c = new $a; //Aオブジェクト3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Class(c) { | |
| if (c == null) { | |
| c = function(){}; | |
| } | |
| c.extend = _extends; | |
| c.mixin = _mixin; | |
| c.statics = _static; | |
| return c; | |
| } | |
| function _extends(uber) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var global = this; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function namespace(str) { | |
| var names=str.split(".") | |
| , i, l, cur = Function("return this")() | |
| ; | |
| for (i=0,l=names.length; i<l; i++) { | |
| cur[names[i]] = cur[names[i]] || {}; | |
| cur = cur[names[i]]; | |
| } | |
| return cur; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var a = "global"; | |
| with ({a:"local"}) { | |
| console.log(a); //"local" | |
| with ({a:"local2"}) { /* 入れ子にできる */ | |
| console.log(a); //"local2" | |
| } | |
| console.log(a); //"local" | |
| } | |
| console.log(a); //"global" |