• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 446
  • Last Modified:

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>
0
ninjadude12
Asked:
ninjadude12
1 Solution
 
tsmgeekCommented:
you
$slide = new Jquery();

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

Open in new window


note the error with $slide1->animate when it should be $slide->animate
0
 
Ray PaseurCommented:
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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now