Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12373561
CodeVariable.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
CodeVariable.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Keruald\OmniTools\Reflection
;
class
CodeVariable
{
private
mixed
$variable
;
///
/// Constructor
///
public
static
function
from
(
mixed
$variable
)
:
self
{
$instance
=
new
self
;
$instance
->
variable
=
$variable
;
return
$instance
;
}
///
/// Type helper methods
///
public
function
hasType
(
string
$type
)
:
bool
{
$ourType
=
gettype
(
$this
->
variable
);
// For scalar types, gettype() doesn't return the same types
// as does reflection classes.
return
match
(
$ourType
)
{
"boolean"
=>
$type
===
"bool"
||
$type
===
"boolean"
,
"integer"
=>
$type
===
"int"
||
$type
===
"integer"
,
"double"
=>
$type
===
"float"
||
$type
===
"double"
,
"object"
=>
$this
->
variable
::
class
===
$type
,
default
=>
$ourType
===
$type
,
};
}
public
function
getType
()
:
string
{
$type
=
gettype
(
$this
->
variable
);
// For scalar types, gettype() doesn't return the same types
// as does reflection classes.
return
match
(
$type
)
{
"boolean"
=>
"bool"
,
"integer"
=>
"int"
,
"double"
=>
"float"
,
"object"
=>
$this
->
variable
::
class
,
default
=>
$type
,
};
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 1, 17:53 (1 d, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3116602
Default Alt Text
CodeVariable.php (1 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment