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

How can I avoid this issue? #2256

Open
navisoft opened this issue Jul 23, 2021 · 1 comment
Open

How can I avoid this issue? #2256

navisoft opened this issue Jul 23, 2021 · 1 comment
Labels
bug Hacktoberfest See https://hacktoberfest.digitalocean.com/ for participants details

Comments

@navisoft
Copy link

navisoft commented Jul 23, 2021

public function getModel(className, args = null) {
    if class_exists("App\\" . className) {
        echo "E";
        var_dump(className);
        let className = "App\\" . className;
    } else {
        echo "N";
        var_dump(className);
        let className = "Default\\" . className;
    }
    return new {className}(args);
}

I have the class "App\Product" and when I use the function getModel("Product"), it's error. After check class_exists("App\" . className), the variable className becomes null and then the final className is "App\" and it causes issue.

@Jeckerson
Copy link
Member

Jeckerson commented Jul 23, 2021

Try to use separate variable for full class name with namespace:

string class;

if class_exists() {
    let class = "App\\" . className;
} else {
    let class = "Default\\" . className;
}

@Jeckerson Jeckerson added the bug label Jul 23, 2021
@Jeckerson Jeckerson added this to the 0.15.0 milestone Sep 12, 2021
@Jeckerson Jeckerson added the Hacktoberfest See https://hacktoberfest.digitalocean.com/ for participants details label Oct 3, 2021
@Jeckerson Jeckerson modified the milestones: 0.15.0, Backlog Oct 5, 2021
@Jeckerson Jeckerson removed this from the Backlog milestone Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Hacktoberfest See https://hacktoberfest.digitalocean.com/ for participants details
Projects
None yet
Development

No branches or pull requests

2 participants