1

I'm retreiving a string and I would like to call it as a new class

I've tried : $class = eval("new $string()") but it's not working.

$class = eval("new {$string}()");
1
  • 2
    eval("\$class = new {$string}()"); Commented Nov 4, 2019 at 12:24

1 Answer 1

1

You don't need eval for that.

$class = new $string();
Sign up to request clarification or add additional context in comments.

2 Comments

Why was this downvoted ? It actually answers the question
@cid It was downvoted, because we shouldn't answer trivial duplicates.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.