b3nj Posted January 11, 2007 Share Posted January 11, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/33786-eval-not-working-with-object-variable/ Share on other sites More sharing options...
Ninjakreborn Posted January 11, 2007 Share Posted January 11, 2007 use something other than eval Quote Link to comment https://forums.phpfreaks.com/topic/33786-eval-not-working-with-object-variable/#findComment-158450 Share on other sites More sharing options...
b3nj Posted January 11, 2007 Author Share Posted January 11, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/33786-eval-not-working-with-object-variable/#findComment-158463 Share on other sites More sharing options...
Ninjakreborn Posted January 11, 2007 Share Posted January 11, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/33786-eval-not-working-with-object-variable/#findComment-158466 Share on other sites More sharing options...
Ninjakreborn Posted January 11, 2007 Share Posted January 11, 2007 well, search eval, I found out some stuff about vuneribilities, it didn't sound too promising at php.net either. Quote Link to comment https://forums.phpfreaks.com/topic/33786-eval-not-working-with-object-variable/#findComment-158474 Share on other sites More sharing options...
b3nj Posted January 12, 2007 Author Share Posted January 12, 2007 oh ok, i didn't know that about eval - i'll go for a different approach then. Thanks very much for your advice. Quote Link to comment https://forums.phpfreaks.com/topic/33786-eval-not-working-with-object-variable/#findComment-158928 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.