The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> eval function
tudsy
post May 18 2022, 08:23 AM
Post #1


Advanced Member
****

Group: Members
Posts: 246
Joined: 30-September 14
Member No.: 21,611



Hi

I am new to the eval function but I was wondering can anyone find anything wrong with this code:


foreach ($this->subclient_names as $subclient_name) {
eval("\$api_instance = \"new /home/ecovibdc/vendor/klaviyo/sdk/API/ ${subclient_name}/Api(new /home/ecovibdc/vendor/guzzlehttp/guzzle/src/Client.php, $this->config\";");

$this->$subclient_name = new Subclient(
$api_instance,
$wait_seconds = 3,
$num_retries = 3,
);


Any help would be appreciated. Thanks Adrian.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
tudsy
post May 18 2022, 12:25 PM
Post #2


Advanced Member
****

Group: Members
Posts: 246
Joined: 30-September 14
Member No.: 21,611



QUOTE(tudsy @ May 18 2022, 10:53 PM) *

Hi

I am new to the eval function but I was wondering can anyone find anything wrong with this code:


foreach ($this->subclient_names as $subclient_name) {
eval("\$api_instance = \"new /home/ecovibdc/vendor/klaviyo/sdk/API/ ${subclient_name}/Api(new /home/ecovibdc/vendor/guzzlehttp/guzzle/src/Client.php, $this->config\";");

$this->$subclient_name = new Subclient(
$api_instance,
$wait_seconds = 3,
$num_retries = 3,
);


Any help would be appreciated. Thanks Adrian.


Problem was a comma in the wrong place.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post May 20 2022, 06:20 AM
Post #3


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



QUOTE

I am new to the eval function but I was wondering can anyone find anything wrong with this code:
eval("\$api_instance = \"new /home/ecovibdc/vendor/klaviyo/sdk/API/ ${subclient_name}/Api(new /home/ecovibdc/vendor/guzzlehttp/guzzle/src/Client.php, $this->config\";");


What is the purpose of eval($parameter)? It runs the php code in the string $parameter, so normally the point is that this string came from a database, or (!!BIG ALERT!!) a string that a user entered. If the string is simply a bit of PHP code, then the above is the same as writing:
[code]
$api_instance = "new /home/ecovibdc/vendor/klaviyo/sdk/API/ ${subclient_name}/Api(new /home/ecovibdc/vendor/guzzlehttp/guzzle/src/Client.php, $this->config";
[code]

So why are you writing the convoluted version?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th March 2024 - 12:47 AM