homar Posted February 2, 2009 Share Posted February 2, 2009 Hello! I'm new to working with classes and object (basically the whole OOP thing). I've written a class and placed it in a file (someclass.php). When I include the class from my script using: include('someclass.php'); Nothing is displayed when I load the script (just a white page). I figure that there must be an error in my class. However, no error messages are output. If I don't include the class file (and intentionally create an error), error messages are displayed. Basically, is there a way to debug the class? Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/143467-solved-no-error-messages-after-including-a-class/ Share on other sites More sharing options...
premiso Posted February 2, 2009 Share Posted February 2, 2009 Without seeing code, you are not going to get much help. Are you instantiating the class? Or just including the class? Quote Link to comment https://forums.phpfreaks.com/topic/143467-solved-no-error-messages-after-including-a-class/#findComment-752567 Share on other sites More sharing options...
rhodesa Posted February 2, 2009 Share Posted February 2, 2009 just loading a class doesn't do anything....you need to initiate an instance of it for any of the code in it to actually run. <?php require_once('someclass.php'); //use require_once instead to make sure it loads and only loads once $obj = new someclass(); print_r($obj); ?> seriously...premiso...this is starting to scare me Quote Link to comment https://forums.phpfreaks.com/topic/143467-solved-no-error-messages-after-including-a-class/#findComment-752569 Share on other sites More sharing options...
homar Posted February 2, 2009 Author Share Posted February 2, 2009 Sorry! I should have mentioned that I used: ClassName::Function($var); Quote Link to comment https://forums.phpfreaks.com/topic/143467-solved-no-error-messages-after-including-a-class/#findComment-752571 Share on other sites More sharing options...
rhodesa Posted February 2, 2009 Share Posted February 2, 2009 can you post the complete code for both files? Quote Link to comment https://forums.phpfreaks.com/topic/143467-solved-no-error-messages-after-including-a-class/#findComment-752573 Share on other sites More sharing options...
premiso Posted February 2, 2009 Share Posted February 2, 2009 just loading a class doesn't do anything....you need to initiate an instance of it for any of the code in it to actually run. <?php require_once('someclass.php'); //use require_once instead to make sure it loads and only loads once $obj = new someclass(); print_r($obj); ?> seriously...premiso...this is starting to scare me lol at least you gave an example I guess I could have been nice and done that too lol. Quote Link to comment https://forums.phpfreaks.com/topic/143467-solved-no-error-messages-after-including-a-class/#findComment-752574 Share on other sites More sharing options...
homar Posted February 2, 2009 Author Share Posted February 2, 2009 Sure, It's kind of long though... <?php ## Change these settings as you please $options = array ( "minLength" => 4, ## minimum allowable password length (int) "maxLength" => 100, ## maximum allowable password length (int) "securePass" => "ir2#cT@d", ## a password that scores 100% (string) "dictionary" => true, ## check dictionary? (bool) "caseSensitive" => true ## does your script accept case sensitive passwords? (bool) ); ## Include required files include('./classes/dictionary.php'); include('./classes/algorithm.php'); ## Password $password = $_REQUEST['pass']; ## Username $username = $_REQUEST['user']; ## Split password into words by numbers (e.g. password1 or 1password is no good) $parts = array_filter(preg_split('/[^a-zA-Z]/',$password)); ## Array to contain identifiable words $words = array(); ## Check the dictionary foreach ($parts as $word) { ## Prevent letters and common combinations being matched if (strlen($word) > 3) { if(SpellChecker::Check(strtolower($word))) { $containsWord = true; ## password contains word $words = array_push($words, $word); ## add identifiable word to array } } } ## Execute the algorithm PasswordStrength::Score($password, $options, $containsWord, $words, $username); ## Output the score echo ($score); ?> <?php class PasswordStrength { ## Constructor private function __construct() {} ## Calculates the number of 1 to n letter words private function numWords($length) { ## The number of english words with n-letters $nLetterWords = array ( "1" => "26", "2" => "99", "3" => "994", "4" => "3957", "5" => "8801", "6" => "15553", "7" => "23674", "8" => "29302", "9" => "24811", "10" => "20192", "11" => "15404", "12" => "11271", "13" => "7780", "14" => "5099", "15" => "3175", "16" => "1942", "17" => "1127", "18" => "595", "19" => "328", "20" => "160", "21" => "62", "22" => "31", "23" => "13", "24" => "9", "25" => "2", "26" => "0", "27" => "2", "27" => "2" ); $i = 1; while ($i < $length) { $numWords += $nLetterWords($i); $i++; } return $numWords; } ## Brute force procedure private function brute($password) { ## Length of the password $passLength = strlen($password); ## Identify whether the password is case sensitive preg_match_all('/[a-z]/', $password, $lowercase); preg_match_all('/[A-Z]/', $password, $uppercase); if (!empty($lowercase)) { $lowercase = count($lowercase[0]); } else { $lowercase = 0; } if (!empty($uppercase)) { $uppercase = count($uppercase[0]); } else { $uppercase = 0; } ## Identify whether the password contains numbers preg_match_all('/[0-9]/', $password, $numbers); if (!empty($numbers)) { $numbers = count($numbers[0]); } else { $numbers = 0; } ## Identify whether the password contains symbols preg_match_all('/[^a-zA-Z0-9]/', $password, $symbols); if (!empty($symbols)) { $symbols = count($symbols[0]); } else { $symbols = 0; } ## Initialize diversity $diversity = 0; ## Case sensitivity, lower case if ((($lowercase > 0) && ($options['caseSensitive'])) { $diversity += 26; } ## Case sensitivity, upper OR lower case if (($uppercase > 0) && ($options['caseSensitive'])) { $diversity += 26; } ## No case sensitivity if (!$options['caseSensitive']) { $diversity += 26; } ## Numbers if ($numbers > 0) { $diversity += 10; } ## Symbols: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ if ($symbols > 0) { $diversity += 32; } $score = ceil(pow($diversity, $passLength)*0.5); return $score; } ## Score the password public function Score($password, $options, $containsWord, $words, $username=NULL) { ## $password: the password to analyse (string) ## $options: execution configuration options (array) ## $containsWord: does the password contain a easily identifiable word (bool) ## $words: array containing identifiable words (array) ## $username: user's username (string) ## Length of the password $passLength = strlen($password); ## Length of the identifiable words $wordsLength = strlen(implode('', $words)); ## Number of words with length 1 to n $numWords = numWords($wordsLength); ## Identify whether the password is a single "real" word if (($containsWord) && ($wordsLength == $passLength)) { ## Identify whether the password is case sensitive preg_match_all('/[a-z]/', $password, $lowercase); preg_match_all('/[A-Z]/', $password, $uppercase); if (!empty($lowercase)) { $lowercase = count($lowercase[0]); } else { $lowercase = 0; } if (!empty($uppercase)) { $uppercase = count($uppercase[0]); } else { $uppercase = 0; } ## Case sensitivity? if ($options['caseSensitive']) { if (($lowercase > 0) && ($uppercase == 0)) || (($lowercase == 0) && ($uppercase > 0)) { ## Only upper case OR only lower case $score = ceil($numWords*0.5); } else { ## Upper case AND lower case $score = ceil(($numWords*0.5) * pow(2, $passLength)); } } else { $score = ceil($numWords*0.5); } } ## Any identifiable words with suffix or prefix elseif (($containsWord) && ($wordsLength != $passLength)) { ## Identify whether the password is case sensitive preg_match_all('/[a-z]/', $password, $lowercase); preg_match_all('/[A-Z]/', $password, $uppercase); if (!empty($lowercase)) { $lowercase = count($lowercase[0]); } else { $lowercase = 0; } if (!empty($uppercase)) { $uppercase = count($uppercase[0]); } else { $uppercase = 0; } ## Case sensitivity? if ($options['caseSensitive']) { if (($lowercase > 0) && ($uppercase == 0)) || (($lowercase == 0) && ($uppercase > 0)) { ## Only upper case OR only lower case $score = ceil(($numWords*0.5) + brute(str_replace($words, "", $password))); } else { ## Upper case AND lower case $score = ceil((($numWords*0.5) * pow(2, $passLength)) + brute(str_replace($words, "", $password))); } } else { $score = ceil($numWords*0.5); } } ## Use brute force procedure else { $score = brute($password); } return $score; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/143467-solved-no-error-messages-after-including-a-class/#findComment-752577 Share on other sites More sharing options...
Snart Posted February 2, 2009 Share Posted February 2, 2009 You need to call the function with an object, not with a descendancy reference: $pw = new PasswordStrength(); echo $pw->Score($password, $options, $containsWord, $words, $username); Quote Link to comment https://forums.phpfreaks.com/topic/143467-solved-no-error-messages-after-including-a-class/#findComment-752579 Share on other sites More sharing options...
homar Posted February 2, 2009 Author Share Posted February 2, 2009 Thanks Snart! I tried your code, but it didn't make a difference. No error message. Nothing Quote Link to comment https://forums.phpfreaks.com/topic/143467-solved-no-error-messages-after-including-a-class/#findComment-752584 Share on other sites More sharing options...
rhodesa Posted February 2, 2009 Share Posted February 2, 2009 calling it statically like you had is fine...but you aren't storing the return value into $score...it should be like so: $score = PasswordStrength::Score($password, $options, $containsWord, $words, $username); p.s. - next time you post code, use [ code ][ /code ] tags (without the spaces)...clicking the button in the toolbar with the # sign does the same thing Quote Link to comment https://forums.phpfreaks.com/topic/143467-solved-no-error-messages-after-including-a-class/#findComment-752589 Share on other sites More sharing options...
PFMaBiSmAd Posted February 2, 2009 Share Posted February 2, 2009 Blank pages are usually the result of fatal parse or fatal runtime errors (or pages that don't output anything.) In your case, you have a fatal parse error - Parse error: parse error in ...\algorithm.php on line 97 It looks like a mis-match of ((( and )) You should be learning php (or learning something new in php), developing php code, and debugging php code on a system where error_reporting is set to E_ALL and display_errors is set to ON in your php.ini to get php to help you (fatal parse errors won't be displayed if you try to turn these settings on in your script.) Edit: and after you fix that error, there is another one at line 166 in that file. Edit2: and another one at line 201. Php error reporting is there to help you. It will save a ton of time. Quote Link to comment https://forums.phpfreaks.com/topic/143467-solved-no-error-messages-after-including-a-class/#findComment-752591 Share on other sites More sharing options...
Snart Posted February 2, 2009 Share Posted February 2, 2009 calling it statically like you had is fine... Cool, I'm learning here too. I like this site. Quote Link to comment https://forums.phpfreaks.com/topic/143467-solved-no-error-messages-after-including-a-class/#findComment-752593 Share on other sites More sharing options...
homar Posted February 2, 2009 Author Share Posted February 2, 2009 Thanks Aaron! I actually had it like that originally. It still doesn't output anything. Also, when I place: echo "test"; above the include, "test" is output. However, if I put it after the include, nothing is displayed. Quote Link to comment https://forums.phpfreaks.com/topic/143467-solved-no-error-messages-after-including-a-class/#findComment-752595 Share on other sites More sharing options...
homar Posted February 2, 2009 Author Share Posted February 2, 2009 Hi PFMaBiSmAd! Thanks for that. Do you know how I can change these settings without php.ini access. I know you can use error_reporting(E_ALL);, but should I put this in my script or the class? Quote Link to comment https://forums.phpfreaks.com/topic/143467-solved-no-error-messages-after-including-a-class/#findComment-752596 Share on other sites More sharing options...
PFMaBiSmAd Posted February 2, 2009 Share Posted February 2, 2009 For fatal parse errors, the settings must be on before your script is parsed. You should be learning, developing, and debugging on a local development system on your PC where you would have access to the php.ini. If php is running as an Apache module, you can put the equivalent settings in a .htaccess file. the E_ALL must be converted to the corresponding integer value because the constant E_ALL does not exist at the .htaccess level. If php is running as a CGI application, you can put the settings in a local php.ini. Quote Link to comment https://forums.phpfreaks.com/topic/143467-solved-no-error-messages-after-including-a-class/#findComment-752598 Share on other sites More sharing options...
rhodesa Posted February 2, 2009 Share Posted February 2, 2009 I think i got all your issues...i made comments where i made changes: <?php class PasswordStrength { ## Constructor private function __construct() {} ## Calculates the number of 1 to n letter words private static function numWords($length) //Made this function static { ## The number of english words with n-letters $nLetterWords = array ( "1" => "26", "2" => "99", "3" => "994", "4" => "3957", "5" => "8801", "6" => "15553", "7" => "23674", "8" => "29302", "9" => "24811", "10" => "20192", "11" => "15404", "12" => "11271", "13" => "7780", "14" => "5099", "15" => "3175", "16" => "1942", "17" => "1127", "18" => "595", "19" => "328", "20" => "160", "21" => "62", "22" => "31", "23" => "13", "24" => "9", "25" => "2", "26" => "0", "27" => "2", "27" => "2" ); $i = 1; while ($i < $length) { $numWords += $nLetterWords($i); $i++; } return $numWords; } ## Brute force procedure private static function brute($password) //Made this function static { ## Length of the password $passLength = strlen($password); ## Identify whether the password is case sensitive preg_match_all('/[a-z]/', $password, $lowercase); preg_match_all('/[A-Z]/', $password, $uppercase); if (!empty($lowercase)) { $lowercase = count($lowercase[0]); } else { $lowercase = 0; } if (!empty($uppercase)) { $uppercase = count($uppercase[0]); } else { $uppercase = 0; } ## Identify whether the password contains numbers preg_match_all('/[0-9]/', $password, $numbers); if (!empty($numbers)) { $numbers = count($numbers[0]); } else { $numbers = 0; } ## Identify whether the password contains symbols preg_match_all('/[^a-zA-Z0-9]/', $password, $symbols); if (!empty($symbols)) { $symbols = count($symbols[0]); } else { $symbols = 0; } ## Initialize diversity $diversity = 0; ## Case sensitivity, lower case if ((($lowercase > 0) && ($options['caseSensitive']))) { //Missing a Left Parenthesis here $diversity += 26; } ## Case sensitivity, upper OR lower case if (($uppercase > 0) && ($options['caseSensitive'])) { $diversity += 26; } ## No case sensitivity if (!$options['caseSensitive']) { $diversity += 26; } ## Numbers if ($numbers > 0) { $diversity += 10; } ## Symbols: !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ if ($symbols > 0) { $diversity += 32; } $score = ceil(pow($diversity, $passLength)*0.5); return $score; } ## Score the password public static function Score($password, $options, $containsWord, $words, $username=NULL) //Made this function static { ## $password: the password to analyse (string) ## $options: execution configuration options (array) ## $containsWord: does the password contain a easily identifiable word (bool) ## $words: array containing identifiable words (array) ## $username: user's username (string) ## Length of the password $passLength = strlen($password); ## Length of the identifiable words $wordsLength = strlen(implode('', $words)); ## Number of words with length 1 to n $numWords = self::numWords($wordsLength); //Added self:: here ## Identify whether the password is a single "real" word if (($containsWord) && ($wordsLength == $passLength)) { ## Identify whether the password is case sensitive preg_match_all('/[a-z]/', $password, $lowercase); preg_match_all('/[A-Z]/', $password, $uppercase); if (!empty($lowercase)) { $lowercase = count($lowercase[0]); } else { $lowercase = 0; } if (!empty($uppercase)) { $uppercase = count($uppercase[0]); } else { $uppercase = 0; } ## Case sensitivity? if ($options['caseSensitive']) { if (($lowercase > 0) && ($uppercase == 0) || (($lowercase == 0) && ($uppercase > 0))) //Missplaces Parenthesis here { ## Only upper case OR only lower case $score = ceil($numWords*0.5); } else { ## Upper case AND lower case $score = ceil(($numWords*0.5) * pow(2, $passLength)); } } else { $score = ceil($numWords*0.5); } } ## Any identifiable words with suffix or prefix elseif (($containsWord) && ($wordsLength != $passLength)) { ## Identify whether the password is case sensitive preg_match_all('/[a-z]/', $password, $lowercase); preg_match_all('/[A-Z]/', $password, $uppercase); if (!empty($lowercase)) { $lowercase = count($lowercase[0]); } else { $lowercase = 0; } if (!empty($uppercase)) { $uppercase = count($uppercase[0]); } else { $uppercase = 0; } ## Case sensitivity? if ($options['caseSensitive']) { if (($lowercase > 0) && ($uppercase == 0) || (($lowercase == 0) && ($uppercase > 0))) //Misplaced Parenthesis here { ## Only upper case OR only lower case $score = ceil(($numWords*0.5) + self::brute(str_replace($words, "", $password))); //Needed self:: here } else { ## Upper case AND lower case $score = ceil((($numWords*0.5) * pow(2, $passLength)) + self::brute(str_replace($words, "", $password))); //Needed self:: here } } else { $score = ceil($numWords*0.5); } } ## Use brute force procedure else { $score = self::brute($password); //Needed self:: here } return $score; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/143467-solved-no-error-messages-after-including-a-class/#findComment-752606 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.