|
| 1 | +--TEST-- |
| 2 | +imageaffinematrixget() translate option conversions |
| 3 | +--EXTENSIONS-- |
| 4 | +gd |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | + |
| 8 | +$resource = fopen(__FILE__, 'r'); |
| 9 | +$values = [ |
| 10 | + 'null' => null, |
| 11 | + 'false' => false, |
| 12 | + 'true' => true, |
| 13 | + 'int' => 42, |
| 14 | + 'float' => 42.5, |
| 15 | + 'numeric integer string' => '42', |
| 16 | + 'numeric float string' => '42.5', |
| 17 | + 'numeric scientific string' => '1e3', |
| 18 | + 'non-numeric string' => 'not numeric', |
| 19 | + 'array' => [], |
| 20 | + 'object' => new stdClass(), |
| 21 | + 'resource' => $resource, |
| 22 | +]; |
| 23 | + |
| 24 | +foreach ($values as $name => $value) { |
| 25 | + echo "$name:\n"; |
| 26 | + try { |
| 27 | + $matrix = imageaffinematrixget(IMG_AFFINE_TRANSLATE, ['x' => $value, 'y' => 0]); |
| 28 | + var_dump($matrix[4]); |
| 29 | + } catch (Throwable $e) { |
| 30 | + echo $e::class, ': ', $e->getMessage(), "\n"; |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +echo "references:\n"; |
| 35 | +$x = 1.5; |
| 36 | +$y = 2.5; |
| 37 | +$matrix = imageaffinematrixget(IMG_AFFINE_TRANSLATE, ['x' => &$x, 'y' => &$y]); |
| 38 | +var_dump($matrix[4], $matrix[5]); |
| 39 | + |
| 40 | +echo "invalid y:\n"; |
| 41 | +try { |
| 42 | + imageaffinematrixget(IMG_AFFINE_TRANSLATE, ['x' => 0, 'y' => []]); |
| 43 | +} catch (Throwable $e) { |
| 44 | + echo $e::class, ': ', $e->getMessage(), "\n"; |
| 45 | +} |
| 46 | + |
| 47 | +echo "trailing data:\n"; |
| 48 | +$matrix = imageaffinematrixget(IMG_AFFINE_TRANSLATE, ['x' => '42 with trailing data', 'y' => 0]); |
| 49 | +var_dump($matrix[4]); |
| 50 | + |
| 51 | +echo "warning converted to exception:\n"; |
| 52 | +set_error_handler(static function (int $errno, string $errstr): never { |
| 53 | + throw new Exception($errstr); |
| 54 | +}); |
| 55 | +try { |
| 56 | + imageaffinematrixget(IMG_AFFINE_TRANSLATE, ['x' => '42 with trailing data', 'y' => 0]); |
| 57 | +} catch (Throwable $e) { |
| 58 | + echo $e::class, ': ', $e->getMessage(), "\n"; |
| 59 | +} |
| 60 | + |
| 61 | +fclose($resource); |
| 62 | + |
| 63 | +?> |
| 64 | +--EXPECTF-- |
| 65 | +null: |
| 66 | +float(0) |
| 67 | +false: |
| 68 | +float(0) |
| 69 | +true: |
| 70 | +float(1) |
| 71 | +int: |
| 72 | +float(42) |
| 73 | +float: |
| 74 | +float(42.5) |
| 75 | +numeric integer string: |
| 76 | +float(42) |
| 77 | +numeric float string: |
| 78 | +float(42.5) |
| 79 | +numeric scientific string: |
| 80 | +float(1000) |
| 81 | +non-numeric string: |
| 82 | +TypeError: imageaffinematrixget(): Argument #2 ($options) "x" key must be of type float, string given |
| 83 | +array: |
| 84 | +TypeError: imageaffinematrixget(): Argument #2 ($options) "x" key must be of type float, array given |
| 85 | +object: |
| 86 | +TypeError: imageaffinematrixget(): Argument #2 ($options) "x" key must be of type float, stdClass given |
| 87 | +resource: |
| 88 | +TypeError: imageaffinematrixget(): Argument #2 ($options) "x" key must be of type float, resource given |
| 89 | +references: |
| 90 | +float(1.5) |
| 91 | +float(2.5) |
| 92 | +invalid y: |
| 93 | +TypeError: imageaffinematrixget(): Argument #2 ($options) "y" key must be of type float, array given |
| 94 | +trailing data: |
| 95 | + |
| 96 | +Warning: A non-numeric value encountered in %s on line %d |
| 97 | +float(42) |
| 98 | +warning converted to exception: |
| 99 | +Exception: A non-numeric value encountered |
0 commit comments