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
Share on other sites


thanks for your help. I will use something else if there's no alternative - but i'd quite like to understand why this method isn't working, as it seems to me that it should be ok. Is there a reason why eval shouldn't be used on object variables?   
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.