Jump to content

Recommended Posts

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
  * htmlpro@gmail.com, 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

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.