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 | |
$a1 = [10,20,30]; //配列っぽい配列 | |
$a2 = [2=>10, 0=>20, 1=>30]; //添え字は整数だが順番が変な配列 | |
$a3 = ['a'=>10, 20, 30]; //添え字に文字列が混じってる |
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
console.log(typeOf(undefined)); //'undefined' | |
console.log(typeOf(null)); //'null' | |
console.log(typeOf("str")); //'string' | |
console.log(typeOf(new String("str"))); //'String' | |
console.log(typeOf(true)); //'boolean' | |
console.log(typeOf(new Boolean(true))); //'Boolean' | |
console.log(typeOf(1)); //'number' | |
console.log(typeOf(NaN)); //'NaN' | |
console.log(typeOf(Infinity)); //'Infinity' | |
console.log(typeOf(-Infinity)); //'-Infinity' |
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 http = require('http'); | |
http.createServer(function(req, res){ | |
var i = 0; | |
var id = 100 * Math.random() | 0; | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
setInterval(function(){ | |
var result = id + ':' + ++i; | |
console.log(result); |
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 Point | |
{ | |
private $x, $y; | |
public function __construct($this->x, $this->y); | |
} |
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 | |
namespace My\Temp; | |
if (!function_exists('My\Temp\getConfig')) { | |
function getConfig() { | |
static $config; | |
if (!$config) { | |
$config = ['hoge' => 'fuga']; | |
} |
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 | |
/** | |
* Twitter風の「約○○分前」を計算する関数 | |
* @param DateTime $target | |
* @param DateTime $now 基準時間をずらしたい場合に指定。 | |
* @return string | |
*/ | |
function toLastUpdateString(DateTime $target, DateTime $now=null) | |
{ | |
if (!$now) $now = new DateTime('@' . $_SERVER['REQUEST_TIME']); |
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 { | |
private function echoClass() { | |
echo 'A', PHP_EOL; | |
} | |
public function p() { | |
$this->echoClass(); | |
} | |
} |
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 Hoge { | |
function __toString() { | |
throw new Exception; | |
} | |
} | |
try { | |
$hoge = new Hoge; | |
echo $hoge; |
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 | |
switch (true) { | |
case 0: | |
echo '数字の0'; | |
break; | |
case '0': | |
echo '文字列の0'; | |
break; | |
case '0.0': | |
echo '文字列の0.0'; |
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 | |
function doSomething($hoge=__LINE__) { | |
var_dump($hoge); | |
} |