Skip to content

Commit 72896bc

Browse files
committed
add typeof()
1 parent 8e63791 commit 72896bc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Operators/typeof.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/** @param mixed $value TODO: Specify type */
6+
function typeof($value): string {
7+
if ($value instanceof JSString) {
8+
$reflectionClass = new ReflectionClass($value);
9+
$isPrimitiveProperty = $reflectionClass->getProperty('isPrimitive');
10+
$isPrimitiveProperty->setAccessible(true);
11+
$isPrimitive = (bool) $isPrimitiveProperty->getValue($value);
12+
13+
if ($isPrimitive) {
14+
return 'string';
15+
}
16+
}
17+
18+
return 'object';
19+
}

0 commit comments

Comments
 (0)