Converts an (IPv4) Internet network address into a string in Internet standard dotted format */
PHP_FUNCTION(long2ip)
{
- zval **num;
+ /* "It's a long but it's not, PHP ints are signed */
+ char *ip;
+ int ip_len;
unsigned long n;
struct in_addr myaddr;
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ip, &ip_len) == FAILURE) {
+ return;
}
- convert_to_string_ex(num);
-
- n = strtoul(Z_STRVAL_PP(num), NULL, 0);
+
+ n = strtoul(ip, NULL, 0);
myaddr.s_addr = htonl(n);
RETURN_STRING(inet_ntoa(myaddr), 1);
-- Testing ip2long() function with Zero arguments --
-Warning: Wrong parameter count for ip2long() in %s on line %d
+Warning: ip2long() expects exactly 1 parameter, 0 given in %s on line %d
NULL
-- Testing ip2long() function with more than expected no. of arguments --
-Warning: Wrong parameter count for ip2long() in %s on line %d
+Warning: ip2long() expects exactly 1 parameter, 2 given in %s on line %d
NULL
===DONE===
bool(false)
--empty array--
-Error: 8 - Array to string conversion, %s(%d)
-bool(false)
+Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d)
+NULL
--int indexed array--
-Error: 8 - Array to string conversion, %s(%d)
-bool(false)
+Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d)
+NULL
--associative array--
-Error: 8 - Array to string conversion, %s(%d)
-bool(false)
+Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d)
+NULL
--nested arrays--
-Error: 8 - Array to string conversion, %s(%d)
-bool(false)
+Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d)
+NULL
--uppercase NULL--
bool(false)
bool(false)
--instance of classWithoutToString--
-Error: 4096 - Object of class classWithoutToString could not be converted to string, %s(%d)
-Error: 8 - Object of class classWithoutToString to string conversion, %s(%d)
-bool(false)
+Error: 2 - ip2long() expects parameter 1 to be string, object given, %s(%d)
+NULL
--undefined var--
bool(false)
bool(false)
--resource--
-bool(false)
+Error: 2 - ip2long() expects parameter 1 to be string, resource given, %s(%d)
+NULL
===DONE===
\ No newline at end of file
int(1118019956)
string(14) "66.163.161.116"
-Warning: Wrong parameter count for ip2long() in %s on line %d
+Warning: ip2long() expects exactly 1 parameter, 0 given in %s on line %d
NULL
bool(false)
bool(false)
int(1869573999)
-Notice: Array to string conversion in %s on line %d
-bool(false)
+Warning: ip2long() expects parameter 1 to be string, array given in %s on line %d
+NULL
-Warning: Wrong parameter count for long2ip() in %s on line %d
+Warning: long2ip() expects exactly 1 parameter, 0 given in %s on line %d
NULL
string(13) "255.254.82.80"
string(7) "0.0.0.0"
-Notice: Array to string conversion in %s on line %d
-string(7) "0.0.0.0"
+Warning: long2ip() expects parameter 1 to be string, array given in %s on line %d
+NULL
Done
-- Testing long2ip() function with Zero arguments --
-Warning: Wrong parameter count for long2ip() in %s on line %d
+Warning: long2ip() expects exactly 1 parameter, 0 given in %s on line %d
NULL
-- Testing long2ip() function with more than expected no. of arguments --
-Warning: Wrong parameter count for long2ip() in %s on line %d
+Warning: long2ip() expects exactly 1 parameter, 2 given in %s on line %d
NULL
===DONE===
\ No newline at end of file
string(7) "0.0.0.0"
--empty array--
-Error: 8 - Array to string conversion, %s(%d)
-string(7) "0.0.0.0"
+Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d)
+NULL
--int indexed array--
-Error: 8 - Array to string conversion, %s(%d)
-string(7) "0.0.0.0"
+Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d)
+NULL
--associative array--
-Error: 8 - Array to string conversion, %s(%d)
-string(7) "0.0.0.0"
+Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d)
+NULL
--nested arrays--
-Error: 8 - Array to string conversion, %s(%d)
-string(7) "0.0.0.0"
+Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d)
+NULL
--uppercase NULL--
string(7) "0.0.0.0"
string(7) "0.0.0.0"
--instance of classWithoutToString--
-Error: 4096 - Object of class classWithoutToString could not be converted to string, %s(%d)
-Error: 8 - Object of class classWithoutToString to string conversion, %s(%d)
-string(7) "0.0.0.0"
+Error: 2 - long2ip() expects parameter 1 to be string, object given, %s(%d)
+NULL
--undefined var--
string(7) "0.0.0.0"
string(7) "0.0.0.0"
--resource--
-string(7) "0.0.0.0"
+Error: 2 - long2ip() expects parameter 1 to be string, resource given, %s(%d)
+NULL
===DONE===