Altec Posted January 6, 2009 Share Posted January 6, 2009 I've set up a development server so I don't have to mess around with FTP. I've decided to develop with error_reporting to E_ALL so I can see everything PHP whines about. In this case I'm getting an undefined variable error for $output in this class: <?php /* @author Matej Koval * http://www.codegravity.com/projects/mathguard * * Edited by Steven, author of PYGuestbook, for smaller code size and speed improvements * [email protected], http://www.phreakyourgeek.com/ */ class mathGuard { function produceOutput($prime) { $a = rand() % 10; $b = rand() % 10; $code = mathGuard::generateCode($a,$b,$prime); $output = '<table><tr><td><pre style="font-size:5px; font-weight: bold; color:red; padding:0px; margin: 0px; line-height:4px;">'."\n\n".MathGuard::renderExpression($a,$b).'</pre></td><td><input type="text" name="mathguard_answer" size="2" maxlength="2"/></td></tr></table><input type="hidden" name="mathguard_code" value="'.$code.'" />'; return $output; } function decToBin($dec) { $pattern = '123456789ABCDEFGHIJKLMNOPQRTSTUWXYZ'; $output = ' '; $i = 0; do { if($dec % 2) { $rand = rand() % 34; $output { 2 - $i } = $pattern { $rand }; } else { $output { 2 - $i } = ' '; } $dec = (int) ($dec / 2); $i++; } while($dec > 0); return $output; } function renderExpression($a,$b) { $number = array( array(7,5,5,5,7), array(2,6,2,2,7), array(7,1,7,4,7), array(7,1,7,1,7), array(4,5,7,1,1), array(7,4,7,1,7), array(7,4,7,5,7), array(7,1,1,1,1), array(7,5,7,5,7), array(7,5,7,1,7) ); $plus = array(0,2,7,2,0); $eq = array(0,7,0,7,0); for($line = 0; $line < 5; $line++) { /*start*/$output .= mathGuard::decToBin($number[$a][$line]).' '.mathGuard::decToBin($plus[$line]).' '.mathGuard::decToBin($number[$b][$line]).' '.mathGuard::decToBin($eq[$line])."\n"; $output = str_replace('0',' ',$output); } return $output; } function encode($input,$prime) { return md5($input.date("H").$prime); } function generateCode($a,$b,$prime) { $code = mathGuard::encode($a + $b,$prime); return $code; } function checkResult($mathguard_answer,$mathguard_code,$prime = 37) { $result_encoded = mathGuard::encode($mathguard_answer,$prime); if($result_encoded == $mathguard_code) { return true; } else { return false; } } function insertQuestion($prime = 37) { $output = mathGuard::produceOutput($prime); return $output; } function returnQuestion($prime = 37) { $output = mathGuard::produceOutput($prime); return $output; } } ?> The line is marked with /*start*/. How can I fix this? I tried defining it as a private varibale with it's value to null, but that didn't work. Link to comment https://forums.phpfreaks.com/topic/139655-undefined-variable/ Share on other sites More sharing options...
sasa Posted January 6, 2009 Share Posted January 6, 2009 declare variable at start of function $output = ''; Link to comment https://forums.phpfreaks.com/topic/139655-undefined-variable/#findComment-730705 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.