Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added test
  • Loading branch information
hikari-no-yume committed Sep 16, 2014
commit a1711cee1714d9cc4c4a2f18b3a45f195e5a2adf
58 changes: 58 additions & 0 deletions tests/lang/operators/coalesce.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
--TEST--
Test ?? operator
--FILE--
<?php

$var = 7;
$var2 = NULL;

$obj = new StdClass;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stdClass

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class names are case-insensitive, it really doesn't matter.

$obj->boo = 7;

$arr = [
2 => 7,
"foo" => "bar",
"foobar" => NULL,
"qux" => $obj,
"bing" => [
"bang"
]
];

var_dump($nonexistant_variable ?? 3);
echo PHP_EOL;
var_dump($var ?? 3);
var_dump($var2 ?? 3);
echo PHP_EOL;
var_dump($obj->boo ?? 3);
var_dump($obj->bing ?? 3);
var_dump($arr["qux"]->boo ?? 3);
var_dump($arr["qux"]->bing ?? 3);
echo PHP_EOL;
var_dump($arr[2] ?? 3);
var_dump($arr["foo"] ?? 3);
var_dump($arr["foobar"] ?? 3);
var_dump($arr["qux"] ?? 3);
var_dump($arr["bing"][0] ?? 3);
var_dump($arr["bing"][1] ?? 3);
?>
--EXPECTF--
int(3)

int(7)
int(3)

int(7)
int(3)
int(7)
int(3)

int(7)
string(3) "bar"
int(3)
object(stdClass)#%d (%d) {
["boo"]=>
int(7)
}
string(4) "bang"
int(3)