Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Console] TableCell Helper throws error if value is numeric #21429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jaydiablo opened this issue Jan 27, 2017 · 4 comments
Closed

[Console] TableCell Helper throws error if value is numeric #21429

jaydiablo opened this issue Jan 27, 2017 · 4 comments

Comments

@jaydiablo
Copy link
Contributor

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 2.7+

When using the TableCell helper in the Console Component, if I pass a numeric value as the first parameter of the constructor, then render the table, PHP throws an error:

Method Symfony\Component\Console\Helper\TableCell::__toString() must return a string value

Sample code:

$table = new Table($output);
$table->setRows([[new TableCell(12345)]]);
$table->render();

Casting to a string (either in the TableCell helper, or before the value is passed to the constructor) fixes it.

@chalasr
Copy link
Member

chalasr commented Jan 27, 2017

But the TableCell constructor expects a string as stated in the phpdoc: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Helper/TableCell.php#L35

@javiereguiluz
Copy link
Member

@chalasr you are right ... but don't you think it's super common to use tables to display numeric values?

@chalasr
Copy link
Member

chalasr commented Jan 27, 2017

I agree and don't see any technical drawback for changing this on 2.7. I just think that, theoretically, this should be considered as an enhancement since it involves to change string to string|int in the doc block (if it was a concrete typehint, we would be stuck until 4.0). Up to deciders :)

@stof
Copy link
Member

stof commented Jan 27, 2017

If there was a string typehint, there would be no bug, as PHP would cast it for us (unless you use strict_types in your own code, but then it would be your responsibility to pass a string strictly, and your choice to use strict mode).

I suggest casting in the constructor though (behaving the same than the string typehint) and keeping it documented as @var string only.

jaydiablo added a commit to jaydiablo/symfony that referenced this issue Jan 27, 2017
fabpot added a commit that referenced this issue Feb 3, 2017
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.
@fabpot fabpot closed this as completed Feb 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants