Jump to content

eval not working with object variable?!?


b3nj

Recommended Posts


This seems like it's just a basic error on my part, but I can't see where. I've have been struggling with it for ages and am not getting anywhere - please could somebody take a look and see where i'm going wrong...

I have a table object, and I want to pass in a string to format a result set:

$tbl = new table('members');
$tbl->formatRow="<tr><td>{$row[0]}</td></tr>";

And then within the table class:

echo (eval('?>' . $this->formatRow . '<?php '));

But this just returns "<tr><td></td></tr>".

If I assign $this->formatRow the string within the class itself:

$this->formatRow="<tr><td>{$row[0]}</td></tr>";
echo (eval('?>' . $this->formatRow . '<?php '));

it does work. So it just doesn't evaluate the variable if its passed in from outside the class. I have checked that the variable isn't getting overwritten anywhere (and it is getting the html part of the string). 

Any help greatly appreciated. thank u



 
Link to comment
https://forums.phpfreaks.com/topic/33786-eval-not-working-with-object-variable/
Share on other sites

I really don't know why.  But throughout my entire career, and before that when I was studying, I heard it was very bad to use eval at all.  I even read somewhere, the owner himself repeated these exact words
"If eval is the answer you aren't asking the right questions".  So I think that means quite a bit, I never used it because of that.  Other than that I am not sure.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.