|
30 | 30 | * error whenever it cannot find a class which must be caught. Calling this
|
31 | 31 | * from nr_aws_sdk_php_enable would allow the sdk version value to be set only
|
32 | 32 | * 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. |
36 | 35 | */
|
37 | 36 | void nr_lib_aws_sdk_php_handle_version() {
|
38 | 37 | char* version = NULL;
|
39 | 38 | zval retval;
|
40 | 39 | int result = FAILURE;
|
41 | 40 |
|
42 | 41 | 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. */ |
50 | 53 | 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); |
59 | 56 | }
|
60 | 57 | }
|
61 | 58 |
|
|
0 commit comments