As we upgrade PHP version from 7.4 to 8.1 in Podio Workflow Automation, it is required to update your calculations to be PHP 8 compatible. Until we switch calculations to PHP 8.1, all calculations will be attempted on PHP 8.1 and will fall back to PHP 7.4 upon error so as to generate warnings but avoid disruption to any workflows.
To help with this change, we will now show all PHP notices, warnings, and errors in the flow editor, previews, and flow logs for all calculations. Please refer to the messages below for details on how to fix your calculation. Please check the detailed change list and update the flow as per PHP 8.1.
1.
What did PHP change? String to number comparison.
No error message.
Example Problem: Example 1 0 == ""; PHP 8 calculations will return False.
Example Solution: Example 1 Always compare an integer return value to an integer. substr_count("the dog", "cat") == 0; // True
Reference: |
2.
What did PHP change? Functions requiring arguments will no longer fail silently when missing or empty arguments are passed, or too many arguments are passed.
Error message: Uncaught ArgumentCountError: substr_count() expects at least 2 arguments, 1 given
Example Problem: Example 1 substr_count("the dog"); PHP 8 calculations will return False (due to error) Example 2 substr_count("the dog", ""); PHP 8 calculations will return False (due to error) Example 3 rand(1, 10, 100); PHP 8 calculations will return False (due to error)
Example Solution: Example 1 Always pass required arguments substr_count("the dog", "dog"); // 1 If an argument can be potentially empty (as is common with field token values) you can check for an empty value. $val == "" ? 0 : substr_count("the dog", $val); Only use the exact number of arguments required. rand(1, 10);
Reference: Visit https://www.php.net/ and use the search bar to lookup the manual for the function you are calling. |
3.
What did PHP change? Nested ternary operator requires explicit parentheses in PHP 8.1. Error message: Fatal error: Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)
Example Problem: Example 1 ($val==11 ? "hello" : ($val == 7 ? "test" : $val==11 ? "Foo" : "Bar")); PHP 8 calculations will return False (due to error)
Example Solution: Example 1 Nested ternary should always be wrapped with parentheses. ($val == 11 ? "hello" : ($val == 7 ? "test" : ($val == 11 ? "Foo" : "Bar")));
Reference: https://lindevs.com/nested-ternary-operators-requires-explicit-parentheses-in-php-8-0 |
4.
What did PHP change? Functions will no longer coerce or fail silently if passed an argument of unexpected type.
Error Message: Uncaught TypeError: date(): Argument #2 ($timestamp) must be of type ?int, string given Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, string Uncaught TypeError: number_format(): Argument #1 ($num) must be of type float, string given
Example Problem: Example 1 date($format, "1234567890"); PHP 8 calculations will return False (due to error) Example 2 date('i', ''); PHP 8 calculations will return NULL Example 3 date('Y-m-d H:i:s', '1234567890 -1 hour'); PHP 8 will return False (due to error) Example 4 date('Y-m-d', '2022-02-18'); PHP 8 calculations return False (due to error) Example 5 number_format("1.23"); PHP 8 will return False (due to error)
Example Solution: Example 1 The optional timestamp parameter should be an integer. If the second parameter is passed through as a string (as it it may be with a field token) you can cast to an integer as shown below. date($format, 1234567890);
Always provide a non-empty arguments. If a variable is used and can be potentially empty, you can check ahead. $val == "" ? "N/A" : date('i', $val);
Use strtotime() to generate a relative timestamp. date('Y-m-d H:i:s', strtotime('now -1 hour'));
Again use strtotime() to generate the timestamp value. date('Y-m-d', strtotime('2022-02-18'))
In older PHP versions, float values surrounded by quotes (stringified), could be used as an argument. But in PHP 8 and above we have strict type requirements. As a solution, you may make use of floatval() function to convert stringified float value to pure float. number_format(floatval("1.23")); // 1
Reference: |
5.
What did PHP change? Support for deprecated curly braces for offset access has been removed.
Error Message: Fatal error: Array and string offset access syntax with curly braces is no longer supported
Example Problem: Example 1 $myArray = ["one", "two"]; PHP 8 will return FALSE (due to error)
Example Solution: Example 1 Never use curly braces for string or array offset, only use square brackets. $myArray = ["one", "two"];
Reference: |
6.
What did PHP change? preg_replace() needs 3 compulsory arguments.
Error Message: Uncaught ArgumentCountError: preg_replace() expects at least 3 arguments
Example Problem: Example 1: preg_replace('/foo/', 'bar'); PHP 8 will return False (due to error)
Example Solution: Example 1 Providing less than 3 arguments will throw error. Make sure to provide first 3 compulsory arguments. preg_replace('/foo/', 'bar', 'foobar'); // barbar
Reference: |
7.
What did PHP change? implode() expects its arguments to be array if only 1 argument is provided. or implode() expects its arguments to be string and array if 2 arguments are provided.
Error Message: Uncaught TypeError: implode(): Argument #1 ($pieces) must be of type array, string given
Example Problem: Example 1 implode(['foo', 'bar'], ':') PHP 8 will return False (due to error) Example 2 implode('foo'); PHP 8 will return False (due to error)
Example Solution: Example 1 implode() has changed its signature in PHP 8. If you have a separator, then the first argument must be a string, and the second argument an array. implode(':', ['foo', 'bar']); // foo:bar The first argument must be an array if you specify no separator. implode(['foo', 'bar']); // foobar
Reference: |
8.
What did PHP change? The math functions abs(), ceil(), floor() and round() now properly heed the strict_types directive. Previously, they coerced the first argument even in strict type mode.
Error Message: Uncaught TypeError: floor(): Argument #1 ($num) must be of type int|float, string given.
Example Problem: Example 1 floor("3.14") PHP 8 will return False (due to error)
Example Solution: Example 1 Pass only an integer or float to floor(), abs(), ceil(), and round(). You can cast a string using intval() or floatval(). floor(floatval("3.14")) // 3
Reference: php.net/manual/en/function.floor |
9.
What did PHP change? You can not use a string offset on a string.
Error Message: Uncaught TypeError: Cannot access offset of type string on string
Example Problem: Example 1 'mystring'['a']; PHP 8 calculations will return FALSE
Example Solution: Example 1 Use only integer offsets on strings. 'mystring'[0]; // m |
10.
What did PHP change? Division by zero will now result in an error.
Error Message: Uncaught DivisionByZeroError: Division by zero
Example Problem: Example 1 10/0; PHP 8 calculations will return False (due to error)
Example Solution: Example 1 You can check if your divisor is 0. $var == 0 ? 0 : 10/$var;
|
11.
What did PHP change? Arithmetic with empty strings.
Error Message: Uncaught TypeError: Unsupported operand types
Example Problem: "" + 1; PHP 8 calcs will return False (due to error).
Example Solution: For arithmetic operations, ensure you cast any unknown variable types to an integer. This means you typically want to cast values from field tokens. Note: PWA will attempt to automatically convert empty strings used in arithmetic operations to 0 in your calc at runtime to help avoid this issue. intval("") + 1; // 1
Reference: https://www.php.net/manual/en/migration80.incompatible.php#:~:text=Arithmetic%20operations
|
For more information about the changes in PHP from 7.4 to 8.1, please refer to the below manuals:
- Migrating from PHP 7.4.x to PHP 8.0.x: https://www.php.net/manual/en/migration80.php
- Migrating from PHP 8.0.x to PHP 8.1.x: https://www.php.net/manual/en/migration81.php
Note: A "string" or "argument" example is below:
preg_replace("/(other|work|home):/ism", "", email-field )
In this example, there are 3 strings.
preg_replace("/(other|work|home):/ism"
, ""
, email-field )