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

Error with define if it uses variable in name. #237

Closed
marcimat opened this issue Feb 17, 2022 · 4 comments
Closed

Error with define if it uses variable in name. #237

marcimat opened this issue Feb 17, 2022 · 4 comments

Comments

@marcimat
Copy link

Hi, first of all thanks for PHPDocumentor version 3.3.1-rc which correct #233.
Now I can see another singular issue with constant name when defined like that : define('NOT_OK_' . $v, 'not ok');

Steps to reproduce

Composer.json

{
    "require": {
        "phpdocumentor/reflection": "5.x-dev#3b54c5be5143f5a1e002c3309b27f6af9eb33abf"
    }
}

test.php

<?php
$v = '1';
define('NOT_OK_' . $v, 'not ok');
#echo NOT_OK_1;

run.php

<?php
ini_set('display_errors', 'on');
error_reporting(E_ALL);
include_once 'vendor/autoload.php';
$projectFactory = \phpDocumentor\Reflection\Php\ProjectFactory::createInstance();
$projectFiles = [new \phpDocumentor\Reflection\File\LocalFile('test.php')];
$project = $projectFactory->create('My Project', $projectFiles);
var_dump($project);

execute

php demo.php

gives

Fatal error: Uncaught AssertionError: assert($nameString instanceof String_) in ~/vendor/phpdocumentor/reflection/src/phpDocumentor/Reflection/Php/Factory/Define.php:128

Thanks a lot :)

@jaapio
Copy link
Member

jaapio commented Mar 29, 2022

Hi,

Thanks for your report, The easiest way to fix this would be to ignore dynamic defines. As this library is performing a simple code parsing and not a dynamic analysis of the code, we will not be able to resolve the correct naming for those defines. So I think the best we can get for now is skipping them without an error. Does that make sense to you?

@jaapio
Copy link
Member

jaapio commented Mar 29, 2022

relates to #182

@marcimat
Copy link
Author

That seems good to me. Better than fatal error :)

jaapio added a commit that referenced this issue Apr 2, 2022
Allow semi dynamic defines. Using a minimal implementation of expression
evaluation.

fixes #182, #237
@jaapio
Copy link
Member

jaapio commented Apr 5, 2022

This should have been fixed in v5.2.0

@jaapio jaapio closed this as completed Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants