bug #21430 Casting TableCell value to string. (jaydiablo)
This PR was squashed before being merged into the 2.7 branch (closes #21430).
Discussion
----------
Casting TableCell value to string.
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #21429
| License | MIT
| Doc PR |
PHP throws a catchable fatal error when the value from this method is
used in strstr in the Table class. This fixes the error by casting to a string before returning the value.
Commits
-------
1e5707fed3
Casting TableCell value to string.
This commit is contained in:
commit
f0d13f4708
@ -35,6 +35,10 @@ class TableCell
|
|||||||
*/
|
*/
|
||||||
public function __construct($value = '', array $options = array())
|
public function __construct($value = '', array $options = array())
|
||||||
{
|
{
|
||||||
|
if (is_numeric($value) && !is_string($value)) {
|
||||||
|
$value = (string) $value;
|
||||||
|
}
|
||||||
|
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
|
|
||||||
// check option names
|
// check option names
|
||||||
|
@ -538,6 +538,42 @@ TABLE
|
|||||||
| 1234 |
|
| 1234 |
|
||||||
+------+
|
+------+
|
||||||
|
|
||||||
|
TABLE;
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTableCellWithNumericIntValue()
|
||||||
|
{
|
||||||
|
$table = new Table($output = $this->getOutputStream());
|
||||||
|
|
||||||
|
$table->setRows(array(array(new TableCell(12345))));
|
||||||
|
$table->render();
|
||||||
|
|
||||||
|
$expected =
|
||||||
|
<<<'TABLE'
|
||||||
|
+-------+
|
||||||
|
| 12345 |
|
||||||
|
+-------+
|
||||||
|
|
||||||
|
TABLE;
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTableCellWithNumericFloatValue()
|
||||||
|
{
|
||||||
|
$table = new Table($output = $this->getOutputStream());
|
||||||
|
|
||||||
|
$table->setRows(array(array(new TableCell(12345.01))));
|
||||||
|
$table->render();
|
||||||
|
|
||||||
|
$expected =
|
||||||
|
<<<'TABLE'
|
||||||
|
+----------+
|
||||||
|
| 12345.01 |
|
||||||
|
+----------+
|
||||||
|
|
||||||
TABLE;
|
TABLE;
|
||||||
|
|
||||||
$this->assertEquals($expected, $this->getOutputContent($output));
|
$this->assertEquals($expected, $this->getOutputContent($output));
|
||||||
|
Reference in New Issue
Block a user