-
-
Notifications
You must be signed in to change notification settings - Fork 467
/
ternary.zep
68 lines (54 loc) · 1.18 KB
/
ternary.zep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* Arithmetic operations
*/
namespace Stub;
class Ternary
{
public function testTernary1()
{
return 100 ? true + 100 : false;
}
public function testTernary2(boolean b)
{
return b ? "foo" : "bar";
}
public function testTernaryComplex1(var a, var y)
{
return 100 ? true + 100 : a->y() ? a->x() : isset a[y];
}
public function testTernaryComplex2(var a, var y)
{
return 5 + (100 ? true + 100 : a->y() ? a->x() : isset a[y]);
}
public function testTernaryComplex3(var a)
{
return gettype(typeof a == "resource" ? "unknown": false);
}
/**
* @link https://github.com/zephir-lang/zephir/issues/665
*/
public function testTernaryWithPromotedTemporaryVariable()
{
var var2, var3;
let var2 = ["_b_","_c_"];
let var3 = explode("_", isset(var2[1]) ? var2[1] : "");
return var3;
}
/**
* @link https://github.com/zephir-lang/zephir/issues/297
*/
public function testTernaryAfterLetVariable()
{
var s = 23;
let s = 1===1 ? 3 : 10;
return s;
}
public function testShortTernary(var a) -> var
{
return a ?: false;
}
public function testShortTernaryComplex(var left, var value) -> var|boolean
{
return left ?: value;
}
}