Returns a binary data type of the string passed; data types other than string will first be converted to a string and then returned as binary data.
This function is useful if, for some reason, a string type actually contains binary data; using this function will ensure that all data in the string (even if it contains embedded nulls) is maintained in the binary object (Qore strings must normally be terminated by a single null, so some Qore string operations do not work on binary data with embedded nulls).
binary(string
)
$bin = binary("hello");
Table 3.72. Arguments and Return Values for binary()
Argument Type |
Return Type |
Description |
---|---|---|
String |
Binary |
A binary data type holding the string data passed. |
This function does not throw any exceptions.
Returns a string created from the binary data passed, taking an optional second argument giving the string encoding. If no second argument is passed then the default encoding is assumed.
No checking is performed for embedded null characters or for character encoding violations; the data is simply copied from the binary value to the string (with any embedded nulls, if present), and the string is tagged with the given encoding or with the default encoding if no second argument is passed. See also string() and binary().
binary_to_string(binary, [encoding]
)
$str = binary_to_string($bin, "utf8");
Table 3.73. Arguments and Return Values for binary_to_string()
Argument Type | Return Type | Description |
---|---|---|
Binary, [String] | String | Returns a string corresponding to the binary data passed, taking an optional second argument giving the string encoding. If no second argument is passed then the default encoding is assumed. |
Table 3.74. Exceptions Thrown by binary_to_string()
err | desc |
---|---|
| No binary value was passed as the first argument. |
Converts the argument to a boolean value.
boolean(expression
)
$bool = boolean(1); # returns True
Table 3.75. Arguments and Return Values for boolean()
Argument Type |
Return Type |
Description |
---|---|---|
Any |
Boolean |
Converts the argument to an integer if necessary, where any non-zero value is True, zero is False. |
This function does not throw any exceptions.
Converts the argument to a date and returns the date.
date(expression
)
$date = date(1); # return 1970-01-01T00:00:01
Table 3.76. Arguments and Return Values for date()
Argument Type | Return Type | Description |
---|---|---|
Any | Date | Converts the argument to a date and returns the date. |
This function does not throw any exceptions.
Converts the argument passed to a floating-point value.
float(expression
)
$float = float("1.435"); # returns 1.435
Table 3.77. Arguments and Return Values for float()
Argument Type | Return Type | Description |
---|---|---|
Any | Float | Converts argument passed to a floating-point value. |
This function does not throw any exceptions.
Converts an object or a list to a hash; for any other argument, returns an empty hash (ignores any other arguments passed).
For an object argument, the hash returned is equal to the object members (excluding private members if called outside the class); a list is converted to a hash by taking even numbered list elements (starting with 0) and converting them to strings for the hash keys, and the odd numbered elements following the keys as the key value.
hash(list
|object
)
$h = hash($object); # creates a hash of the object's members
Table 3.78. Arguments and Return Values for hash()
Argument Type | Return Type | Description |
---|---|---|
Object | Hash | Returns a hash of the object's members (public members only if called outside the class). |
List | Hash | Returns a hash by taking even numbered list elements (starting with 0) and converting them to strings for the hash keys, and the odd numbered elements following the keys as the key value. |
anything other than Object or List | Hash | Returns an empty hash. |
This function does not throw any exceptions.
Converts the argument passed to an integer value if it is not already.
int(expression
)
$int = int("200"); # returns 200
Table 3.79. Arguments and Return Values for int()
Argument Type | Return Type | Description |
---|---|---|
Any | Integer | Converts argument passed to an integer value. |
This function does not throw any exceptions.
Returns a list; if any arguments are passed, they are inserted as the first element in the list returned.
list([expression
])
$l = list(200);
Table 3.80. Arguments and Return Values for list()
Argument Type | Return Type | Description |
---|---|---|
[Any ...] | List | Returns a list. If any arguments are passed, they are inserted as the first element in the list returned. |
This function does not throw any exceptions.
Converts the argument passed to a string value.
This function will not convert a binary value to a string; in order to do this, use the binary_to_string() function.
string(expression
)
$str = string(200); # returns "200"
Table 3.81. Arguments and Return Values for string()
Argument Type | Return Type | Description |
---|---|---|
Any | String | Converts the argument passed to a string value. |
This function does not throw any exceptions.
Returns the data type of the argument passed. See Type Constants for the values returned by this function..
type(expression
)
$type = type("hello"); # returns Type::String ("string")
Table 3.82. Arguments and Return Values for type()
Argument Type | Return Type | Description |
---|---|---|
Any | String | Returns the data type of the argument passed. See Type_Constants for the values that can be returned by this function. |
This function does not throw any exceptions.