Including conditional syntax in PHP based on PHP version -
i writing function in php, , in function, i'm trying set can have script call function 1 way if server using php 5.6, , way if on older version. however, when attempt on lower version of php, results in syntax error. wondering if there way force php ignore new syntax entirely rather throwing error if using older version can use script between versions. here code trying with:
if (version_compare(php_version, '5.6.0', '>=')) { // function requires php 5.6+ $stmt->bind_param($type, ...$args); } else { // older versions (slower) call_user_func_array([$stmt, 'bind_param'], array_merge(array($type), $args)); }
syntax parsing runs on different level runtime parsing. php detect syntax error before script gets run , if evaluated.
a possible solution ja͢ck suggests, use 2 script files , conditionally include 1 based on version.
Comments
Post a Comment