Fixing PHP Search Engine scripts

Hi,

I was given a search engine program about two years ago because the original author said he had no time to support it any longer. I figured it was just a case of hosting since I saw no errors when looking at the output from the users side.

A few days ago I discovered phplint and being a huge validator fan (my skills are in CSS and HTML) I ran one of the PHP files through the site and it returned a huge number of errors in the code which I have no clue how to fix. So while I don’t know PHP I would like some help in fixing the errors on each of the PHP files that are part of the search engine and I would like some explanation or comments added to the files so I can at least figure out how the whole package works.

Is this the place to do this type of thing? I don’t want to be a bother so if this is not the place I would greatly appreciate being pointed in the right direction. I can post the scripts, they are my property now and even if they are filled with mistakes they do run…

Hi there,

I’d be the last person on this forum board to say this because I know what all the other contributors might say, but I might as well get it out into the open: if the script is working as intended and no errors pop up at runtime, then there should be no reason to try and fix it. While you might start fixing errors that the validator gives you, you might, in reality, be causing more and more errors in other parts of the code. It’s been working so far I’m guessing so “if it ain’t broke, don’t fix it”.

However, if you are the type of person who just needs to fix any or all of the errors that is in your code, just simply post the scripts that the validator is saying has errors in it and we’ll take a look at it.

Thanks.

Hello again, I forgot I was already registered here :slight_smile:

I am a perfectionist and while the program runs it doesn’t always give the correct results and does show errors in the admin functions area so I do want to get those things fixed.

Should I post the straight script or the phplint output which gives line numbers and shows what it thinks are errors (and warnings)?

Here is the first 100 lines of code output from phplint showing the warnings and errors: [php]1: <?php
13: // START THE TIMER & START COUNTING QUERIES
15: $stats[‘timer’] = array_sum(explode(" “,microtime()));
$stats[‘timer’] = array_sum(explode(” ",microtime()));
_ HERE
==== 15: Warning: calling explode()' declared in modules/standard:427, argument no. 2: found typemixed’, required type `string’

16: $stats[‘queries’] = 0;
25: // ANTI-CHEAT SYSTEM
26: $_SESSION[‘arandomnumber’] = empty($_SESSION[‘arandomnumber’]) ? sha1(time().rand(99,9999)) : $_SESSION[‘arandomnumber’];

    $_SESSION['arandomnumber'] = empty($_SESSION['arandomnumber']) ? sha1(time().rand(99,9999)) : $_SESSION['arandomnumber'];
                                                                          \_ HERE

==== 26: Warning: function `sha1()’ (still) not declared. Guessing signature from its usage. Hint: it’s better to declare the functions before their usage.

37: $settings[‘copyright’] = $settings[‘title’].’ © ‘.$settings[‘author’].’ ‘.$settings[‘author2’].’ ‘.$settings[‘history’].’ :: Version: '.$settings[‘version’];
38: $settings[‘links’] = array(
39: ‘Bugs & Help Forum’ => ‘http://www.runboard.com/btherunboarddirectory.f5’,
40: ‘Add RunSearch To Your Board’ => $settings[‘domain’].‘extras/searchbox’,
41: ‘Link To RunSearch’ => $settings[‘domain’].‘extras/linktous’,
42: ‘The Runboard Directory’ => ‘http://www.runboard.com/btherunboarddirectory
43: );

                                                            );
                                                              \_ HERE

==== 43: ERROR: cannot assign a value of type array[string]string to a variable of type string

59: // ARRAY OF COLOR SCHEMES :wink:
60: $themes = array(
70: // SHOW ERRORS
71: function showErrors() {
73: global $errors;
75: $errs = array(
76: 0 => ‘’,
77: 1 => ‘Too many search terms’,
78: );
79: $_GET[‘e’] = (int) $_GET[‘e’];
80:
81: if(isset($errs[$_GET[‘e’]]))

            if(isset($errs[$_GET['e']]))
                                      \_ HERE

==== 81: ERROR: invalid array index of type mixed
82: $errors = $errs[$_GET[‘e’]];

                    $errors = $errs[$_GET['e']];
                                               \_ HERE

==== 82: ERROR: invalid array index of type mixed
83: }
84:
85: // ADDSLASHES__RECURSIVE
86: function addSlashesRecursive($var)
==== 71: notice: guessed signature of the function `showErrors()’ as void()

    function addSlashesRecursive($var)
                                     \_ HERE

==== 86: ERROR: the name `$var’ is a keyword. This is deprecated by PHP and forbidden by PHPLint.

    function addSlashesRecursive($var)
                                      \_ HERE

==== 86: ERROR: undefined type for argument $var'. Hint: you may indicate an explicit type (example:/.int./ $var’) or assign a default value (example: $var=123') or add a DocBlock line tag (example:@param int $var’).
87: {
88: if (!is_array($var))

            if (!is_array($var))
                              \_ HERE

==== 88: ERROR: the name `$var’ is a keyword. This is deprecated by PHP and forbidden by PHPLint.
89: return addslashes($var);

                    return addslashes($var);
                                          \_ HERE

==== 89: ERROR: the name `$var’ is a keyword. This is deprecated by PHP and forbidden by PHPLint.

                    return addslashes($var);
                                            \_ HERE

==== 89: notice: from this return' we guess the functionaddSlashesRecursive()’ returns a value of type string
90:
91: // ADDS SLASHES TO EVERY ELEMENT AND RECURSIVELY CALLS ITSELF
92: foreach ($var as $k => $v)

            foreach ($var as $k => $v)
                         \_ HERE

==== 92: ERROR: the name `$var’ is a keyword. This is deprecated by PHP and forbidden by PHPLint.
93: $var[$k] = addSlashesRecursive($v);

                    $var[$k] = addSlashesRecursive($v);
                        \_ HERE

==== 93: ERROR: the name `$var’ is a keyword. This is deprecated by PHP and forbidden by PHPLint.

                    $var[$k] = addSlashesRecursive($v);
                            \_ HERE

==== 93: ERROR: invalid array index of type mixed
94:
95: return $var;

            return $var;
                       \_ HERE

==== 95: ERROR: the name `$var’ is a keyword. This is deprecated by PHP and forbidden by PHPLint.

            return $var;
                        \_ HERE

==== 95: ERROR: function addSlashesRecursive()': expected return type string, found expression of type array[]string 96: } 98: // STRIPSLASHESRECURSIVE 99: function stripSlashesRecursive($var) ==== 86: notice: guessed signature of the functionaddSlashesRecursive()’ as string(unknown)

    function stripSlashesRecursive($var)
                                       \_ HERE

==== 99: ERROR: the name `$var’ is a keyword. This is deprecated by PHP and forbidden by PHPLint.

    function stripSlashesRecursive($var)
                                        \_ HERE

==== 99: ERROR: undefined type for argument $var'. Hint: you may indicate an explicit type (example:/.int./ $var’) or assign a default value (example: $var=123') or add a DocBlock line tag (example:@param int $var’).
100: {[/php]This script is a total of 506 lines but I am thinking the most I can actually work with at any given time here is 100 lines. I have zero PHP knowledge for all practical purposes.

Sponsor our Newsletter | Privacy Policy | Terms of Service