PHP fatal error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dharmendra Pardhi
    New Member
    • Aug 2010
    • 1

    PHP fatal error

    Hello everyone,

    Yesterday I was start work on an application that is made in php. this application is running well in my local server. but when I put it online some time it work fine but some time I get fatal error. I have search for that error on web but I could not get required solution. any one that know about this error please reply me.

    "Fatal error: Cannot use object of type userModule as array in /hermes/web01/b2180/" .
    Last edited by Dormilich; Aug 31 '10, 10:39 PM. Reason: spelling
  • Jerry Winston
    Recognized Expert New Member
    • Jun 2008
    • 145

    #2
    These kind of fatal errors happen very very early in a programs development.


    Make sure the module 'userModule" is available and in the proper directory on the new server.
    Last edited by Dormilich; Aug 31 '10, 10:39 PM. Reason: spelling

    Comment

    • wizardry
      New Member
      • Jan 2009
      • 201

      #3
      if you read the log file it should give u a line # where the code is ref. then debug it from there.

      or post your code for the given error.
      Last edited by Dormilich; Aug 31 '10, 10:39 PM. Reason: spelling

      Comment

      • kovik
        Recognized Expert Top Contributor
        • Jun 2007
        • 1044

        #4
        The error "Cannot use X as array" means that you are attempting to access an index of a non-array object. Arrays are something you should typecheck for. There are a few ways to deal with it:
        1. The easy way: Only send arrays to the function.
        2. Typecast objects (generally only stdClass objects work) or scalar data (i.e. strings, integers, etc) to arrays.

          i.e.
          Code:
          function foo($bar) {
              $bar = (array)$bar;
              ...
          }
        3. Restrict the accepted type of the function to array (this can only be done for arrays and objects).

          i.e.
          Code:
          function foo(array $bar) {
              ...
          }
        4. Check that the data you are handling is an array beforehand. Generally if your function accepts non-arrays, you should have another means of handling them.

          i.e.
          Code:
          function foo($bar) {
              if (is_array($bar)) {
                  ...
              } else if (is_scalar($bar)) {
                  ...
              } else {
                  ...
              }
          }

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          note: depending on what array functionality you use, there are some Interfaces that enable objects to do that.

          - for using in foreach() you can implement the Iterator or IteratorAggrega te interface

          - access objects like an array ($obj["prop"]) use the ArrayAccess interface

          - for some of the array functions, appropriate interfaces are available (e.g. Countable for count())

          Comment

          Working...