Function causing script to stop in php

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

PHP 5.5.3 on Apache 2.0 I hate asking what seems to be such a simple question, but I m completely stuck on what may be causing this problem.

I have a function that I wrote to perform a simple calculation in the middle of a simple decision structure. If I include the function as part of the main php file I m working with the file won t run at all. If I put the function in a separate file and require that file the script won t run past the require. If I put the function in a class in a separate file, then require that file and create an object form that class it again stops at the require line. And doesn t throw any errors!

I ve tried it with the same calculation and decision structure basically in the main file, as long as I comment out the require and object creation it runs fine all the way through. As soon as I replace the require and object creation (or past the function into the main file) the problems begin again.

Am I missing something syntactically that s throwing a silent error??? I m really at a loss especially since the problem is on a function (well now a method) this simple!!!!

First.php :

<!DOCTYPE html>
<html>
<head>
    <title>Midi Stuff Sandbox & Testing</title>
</head>

    <body>
<?php
    require( ./fun.class.php );
    $procs = new TheseFunctions();

    $string1 = "This is a string to try.";
    $array1 = explode(" ", $string1);
    echo "<pre>";
    print_r($array1);
    echo "	</pre>
";
    echo $procs->getTempo(4, 7);

    if (strlen($array1[1]) != 0)
    {
        $first = strlen($array1[0]);
        $second = strlen($array1[1]);

        echo "It s: " . ($first / $second);
    }
    else
    {
        echo "WTF" . $array[1];
    }
?>
</body>
</html>

The file with the function in it (I thought maybe it needed to be contained in a class which is why it is here, but whether it is or isn t, or is just part of the original php file it still causes the script to stop without an error): file is fun.class.php

<?php
class TheseFunctions
{

function getTempo($first, $second){

    if ($second != 0)
    {
            $result1; 
            $current;
            $current = ($first / $second);

    } else {
        $current = $first;
    }

    return $current;
}
}
?>

so yeah, I realize I m probably missing something completely obvious, and I have no idea what it is.

  EDIT   

after working on it for 30+ minutes (nothing changed) it seems to be working fine now. I really have no idea why it wasn t (in 3 different ways) nor why it wasn t giving me a particular message. I apologize, but appreciate the answers trying to help. Maybe MAMP was just trying to give me a migraine >.<

Answers

Some servers require you to include files like below, you might try this.

try : require( dirname(__ FILE __). /fun.class.php );

I had this problem on different typres of servers, some accept include other need the dirname combo.

Be sure to check the location of the fun.class !! I think this is the problem really.

You dont really need the two vars in the class that are undefined:

$result1; $current;

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/22038063/function-causing-script-to-stop-in-php

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils