Skip to content
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

Remove concat null (rcn) breaks implicit casting to string #122

Open
pbiggar opened this issue Jun 3, 2015 · 2 comments
Open

Remove concat null (rcn) breaks implicit casting to string #122

pbiggar opened this issue Jun 3, 2015 · 2 comments

Comments

@pbiggar
Copy link
Owner

pbiggar commented Jun 3, 2015

Simple example is the optimizations/concat_null.php test:

<?php
$x = 5;
var_dump ("$x");
?>

Output should be 'string ("5")', but with rcn enabled, we get 'int (5)'.

Perhaps '"$x"' should always be converted to '(string) $x'?

Original issue reported on code.google.com by jimmehc on 2009-08-07 16:42:52

@pbiggar
Copy link
Owner Author

pbiggar commented Jun 3, 2015

Remove_concat_null removes empty concatenation on both left and right ends. Empty right
concatenation can be safely removed, but left concatenations may add an implicit string
cast.

I'm providing a patch (yet unapplied) that removes the left empty operand if the right
operand is a string. In the other cases we still remove the empty operand, but provide
a cast to string for the right expression. I believe that a cast should be faster than
the concatenation.

In the example:
  $x = "" . 5;
It will be converted to:
  $x = (string) 5;

Unfortunately, the wpa pass cannot handle string casts and is causing an exception.
So, we should only remove the left empty operand if the right operand is an string?

Original issue reported on code.google.com by logytech on 2010-09-06 18:10:46


- _Attachment: [rcn.patch](https://storage.googleapis.com/google-code-attachments/phc/issue-113/comment-1/rcn.patch)_

@pbiggar
Copy link
Owner Author

pbiggar commented Jun 3, 2015

The rcn pass was designed to clean up after parsing statements like "$x", rather than
for general code. So perhaps we need to do it only

Perhaps the correct solution is to only apply the transformation when the parser attributes
are there?

Or we could support casting to a string? The difficulty there is that it should call
the object's to_string handler. But if we know we don't have an object, we could just
assign the type of the expression to be a string?

I think either or both or whatever is simplest is fine.

Original issue reported on code.google.com by paul.biggar on 2010-09-07 00:03:29

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

1 participant