Link to home
Start Free TrialLog in
Avatar of ninjadude12
ninjadude12

asked on

Fatal error: Call to a member function Animate() on a non-object in jquery.php on line 38

getting: Fatal error: Call to a member function Animate() on a non-object in jquery.php on line 38


<?php

class Jquery {
      
      function animate($trigger, $element, $event, $time) {
            
            echo "<script>
            
                    $(function() {
                        
                        $('$trigger').$event(function() {
                        
                        $('#$element').slideDown($time);
            
                        });
                        
                      });
   
                  </script>";
            
            ;
      }
}

?>



<?

$trigger= "a";
$element = "paragraph";
$event = "hide";
$time = "500";

$slide = new Jquery();

$slide1->animate($trigger, $element, $event, $time);



?>


<html>
   
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8">
        <title>jquery class</title>
       
    </head>
   
   
   
   
   
</html>
ASKER CERTIFIED SOLUTION
Avatar of tsmgeek
tsmgeek
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think tsmgeek is on the right track here.

If you add error_reporting(E_ALL) to the top of all your scripts, you will get a notice when you try to use an undefined variable.  It will save you from a lot of headscratching over something as simple as a typographical error or a misspelling like this one.

The code snippet shows how to create the error and shows how different error reporting levels can give you different results.  You can test it here:
http://www.laprbass.com/RAY_oop_example_2.php
<?php // RAY_oop_example_2.php
error_reporting(E_ALL);
echo "<pre>" . PHP_EOL; // MAKE IT EASY TO READ THE OUTPUT


// DEMONSTRATE HOW PHP HANDLES UNDEFINED VARIABLES (PROPERTIES)
// AND UNDEFINED FUNCTIONS (METHODS) IN OOP NOTATION.
// NOTE HOW DIFFERENT ERROR REPORTING LEVELS WILL CAUSE DIFFERENT OUTPUT
// MAN PAGE http://php.net/manual/en/language.oop5.php


// DEFINE A CLASS OF TEST DATA
class Thing
{
    // DEFINE SOME PROPERTIES
    public $p1, $p2, $p3;

    // DEFINE A CONSTRUCTOR TO SET THE VALUES OF THE PROPERTIES
    public function __construct()
    {
        $this->p1 = 'One';
        $this->p2 = 'Two';
        $this->p3 = 'Three';
    }
}


// INSTANTIATE AN OBJECT FROM THE Thing CLASS
$x = new Thing;
if (is_object($x)) echo PHP_EOL . "X IS AN OBJECT ";


// SHOW THE CONTENTS OF THE OBJECT
var_dump($x);

// ITERATE OVER THE OBJECT
foreach ($x as $property => $value)
{
    echo PHP_EOL . "$property CONTAINS $value";
}


// FOR CONTRAST, CREATE A NON-OBJECT
$y = array();
if (is_array($y)) echo PHP_EOL . "Y IS AN ARRAY ";

// TRY TO ACCESS A PROPERTY OF A NON-OBJECT
echo PHP_EOL . 'HERE IS Y->PROP' . $y->prop;

// SET THE DEFAULT ERROR REPORTING AND TRY IT AGAIN - NO "NOTICE" SHOWS
error_reporting(E_ALL ^ E_NOTICE);
echo PHP_EOL . 'HERE IS Y->PROP' . $y->prop;

// NOW TRY TO ACCESS A METHOD OF A NON-OBJECT
echo PHP_EOL . $y->test();

Open in new window