Skip to content

Commit f0d13f4

Browse files
committed
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 ------- 1e5707f Casting TableCell value to string.
2 parents ff33768 + 1e5707f commit f0d13f4

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/Symfony/Component/Console/Helper/TableCell.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class TableCell
3535
*/
3636
public function __construct($value = '', array $options = array())
3737
{
38+
if (is_numeric($value) && !is_string($value)) {
39+
$value = (string) $value;
40+
}
41+
3842
$this->value = $value;
3943

4044
// check option names

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,42 @@ public function testRenderMultiByte()
538538
| 1234 |
539539
+------+
540540

541+
TABLE;
542+
543+
$this->assertEquals($expected, $this->getOutputContent($output));
544+
}
545+
546+
public function testTableCellWithNumericIntValue()
547+
{
548+
$table = new Table($output = $this->getOutputStream());
549+
550+
$table->setRows(array(array(new TableCell(12345))));
551+
$table->render();
552+
553+
$expected =
554+
<<<'TABLE'
555+
+-------+
556+
| 12345 |
557+
+-------+
558+
559+
TABLE;
560+
561+
$this->assertEquals($expected, $this->getOutputContent($output));
562+
}
563+
564+
public function testTableCellWithNumericFloatValue()
565+
{
566+
$table = new Table($output = $this->getOutputStream());
567+
568+
$table->setRows(array(array(new TableCell(12345.01))));
569+
$table->render();
570+
571+
$expected =
572+
<<<'TABLE'
573+
+----------+
574+
| 12345.01 |
575+
+----------+
576+
541577
TABLE;
542578

543579
$this->assertEquals($expected, $this->getOutputContent($output));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy