Skip to content

Commit 6c9dd70

Browse files
authored
fix(agent): Use lambda function instead of 2 calls
1 parent bbfdc54 commit 6c9dd70

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

agent/lib_aws_sdk_php.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,29 @@
3030
* error whenever it cannot find a class which must be caught. Calling this
3131
* from nr_aws_sdk_php_enable would allow the sdk version value to be set only
3232
* once. To avoid the VERY unlikely but not impossible fatal error, we need to
33-
* take an extra step to wrap the call in a try/catch block. This means we need
34-
* to have an additionial zend_string_eval to get the result, but we avoid fatal
35-
* errors.
33+
* wrap the call in a try/catch block and make it a lambda so that we avoid
34+
* fatal errors.
3635
*/
3736
void nr_lib_aws_sdk_php_handle_version() {
3837
char* version = NULL;
3938
zval retval;
4039
int result = FAILURE;
4140

4241
result = zend_eval_string(
43-
"$nr_aws_sdk_version = '';"
44-
"try {"
45-
" $nr_aws_sdk_version = Aws\\Sdk::VERSION;"
46-
"} catch(Throwable $_e) {"
47-
"}",
48-
NULL, "Set nr_aws_sdk_version");
49-
42+
"(function() {"
43+
" $nr_aws_sdk_version = '';"
44+
" try {"
45+
" $nr_aws_sdk_version = Aws\\Sdk::VERSION;"
46+
" } catch (Throwable $e) {"
47+
" }"
48+
" return $nr_aws_sdk_version;"
49+
"})();",
50+
&retval, "Get nr_aws_sdk_version");
51+
52+
/* See if we got a non-empty/non-null string for version. */
5053
if (SUCCESS == result) {
51-
result = zend_eval_string("$nr_aws_sdk_version", &retval,
52-
"Get nr_aws_sdk_version");
53-
54-
/* See if we got a non-empty/non-null string for version. */
55-
if (SUCCESS == result) {
56-
if (nr_php_is_zval_non_empty_string(&retval)) {
57-
version = Z_STRVAL(retval);
58-
}
54+
if (nr_php_is_zval_non_empty_string(&retval)) {
55+
version = Z_STRVAL(retval);
5956
}
6057
}
6158

0 commit comments

Comments
 (0)