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

Cassandra\Float "is a reserved word" #3

Closed
downsider opened this issue Sep 6, 2021 · 2 comments
Closed

Cassandra\Float "is a reserved word" #3

downsider opened this issue Sep 6, 2021 · 2 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers question Further information is requested
Milestone

Comments

@downsider
Copy link

I found an issue when using the Cassandra\Float class as a return type hint in PHP 8.0.9

Using the class name directly causes the following error:

PHP Fatal error:  Cannot use Cassandra\Float as Float because 'Float' is a special class name

Even when aliased, the compiler still throws an error, albeit a different one:

PHP Fatal error:  Cannot use 'Cassandra\Float' as class name as it is reserved

Example code

use Cassandra\Float as CassandraFloat;

class Test {

    public function getFloat(float $float): CassandraFloat
    {
        return new CassandraFloat($float);
    }

}

Removing the return type hint solves the problem, but shouldn't be required.

To be honest, this feels like it might be a PHP bug rather than an issue with the Cassandra extension, but it may be something that should be addressed here anyway; "float" is a reserved word and the class name may need to be changed to avoid issues in the future

As far as I can tell the only other "type" that might be an issue is Cassandra\Numeric, but that is only "soft" reserved

@CodeLieutenant
Copy link
Member

CodeLieutenant commented Sep 6, 2021

Hi, and thanks for the report. We know about this bug, and it's been in the library for a very long time. This cannot be solved until we release v2, because this will be breaking change, and we are not ready to port our large codebase to v2 yet. PHP is case insensitive language so it treats Float class as reserved, this is why php-parser names "Float_" and any other type that matches the reserved keyword PHP-Parser Array_ . We plan V2 in the near and the next version will drop support for PHP5 and will address issues like these.

For now, in our codebases we do not type it with cassandra types, we use plain php types (int, float ...) (It's sad, but this is what we must do)

I will leave this issue open, if you have any further questions, please feel free to ask them.

@downsider
Copy link
Author

Thanks for your reply and for letting me know your plans

I am very grateful for your work on this extension. My company had been planning on using ODBC as a replacement for the Datastax extension, until we found that it couldn't handle setting TTLs on a column. There was a mild panic before we found your PHP8 version and all was well again :)

I will keep an eye out for the v2 release

@CodeLieutenant CodeLieutenant added question Further information is requested v2 Will be implemented in version 2 labels Sep 7, 2021
@CodeLieutenant CodeLieutenant self-assigned this Sep 7, 2021
@CodeLieutenant CodeLieutenant pinned this issue Sep 7, 2021
CodeLieutenant pushed a commit that referenced this issue May 10, 2022
Signed-off-by: Dusan Malusev <dmalusev@nanointeractive.com>
CodeLieutenant pushed a commit that referenced this issue May 10, 2022
Signed-off-by: Dusan Malusev <dmalusev@nanointeractive.com>
CodeLieutenant pushed a commit that referenced this issue May 10, 2022
Signed-off-by: Dusan Malusev <dmalusev@nanointeractive.com>
@CodeLieutenant CodeLieutenant added this to the v1.4.0 milestone May 28, 2023
@CodeLieutenant CodeLieutenant added bug Something isn't working good first issue Good for newcomers and removed v2 Will be implemented in version 2 labels May 28, 2023
@CodeLieutenant CodeLieutenant modified the milestones: v1.4.0, v2.0.0 Aug 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants