Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Fatal error: Call to a member function query() on a non-object

  1. #11
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    1. It is a good idea to learn with the newest trend and not learn any old bad habits.
    this is definitely my biggest concern but i take care of a handful of projects that are on shared servers. most are on 5.2 so i think i will use the same on localhost for now

  2. #12
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    If you're stuck with a particular version of PHP (i.e., on a shared server), then there is good cause to revert your local development version.

    However, even in 5.2, using a reference to instantiate a class was not proper procedure - it just threw a notice, rather than a warning (which probably never made it to your screen). I can't find anything to indicate that it was ever used in any 5.x version; the only mentions I've found seem to place it in version 4, when OO programming was just being introduced to PHP (and not very well, to be blunt).

    all in all, it just doesn't make any sense: the reference operator means you intend to work with the same contents as that which you're referencing. for example:
    PHP Code:
    $myvar 'value';
    $urvar $myvar;
    $myref =& $myvar;

    print 
    $myvar."\n".$urvar."\n".$myref;
    // prints:
    // value
    // value
    // value

    $myref 'other value';

    print 
    $myvar."\n".$urvar."\n".$myref;
    // prints:
    // other value
    // value
    // other value 
    in this example, $myvar and $myref literally share the same value (not identical values, but actually two names for one box, as it were), whereas the value of $urvar is simply identical to $myvar (at the time it was assigned: it's a "copy").

    doing this when creating a new class instance is pointless because there is no existing value to reference: as the keyword implies, the class instance is "new."

    As I said, I'm just discovering this issue, so I may not have a complete grasp of it, so I'm sorry if something I'm going on about isn't quite right.

    </tangent>

    In any case, it seems the problem you actually had is solved.

  3. The Following User Says Thank You to traq For This Useful Post:

    ggalan (05-07-2011)

  4. #13
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    The problem seems to be &new vs. new. Can you remove the & and see if it works?
    i removed the & and that got rid of the error in php 5.3

  5. #14
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    did it have any negative effect, or any other effect, on code execution under v5.2 (I can't imagine it would, but in the interest of thoroughness)?

  6. #15
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    it worked fine i both 5.2 and 5.3. ive never seen that & sign used in conjunction with a new , was that something common in previous versions of php?

  7. #16
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I'd never seen it before, either. I suspect (though I really don't know) that it was simply an early method of instantiating an object from a class, and was later made obsolete (perhaps due to a change in the object constructor model), but retained for backwards-compatibility. Whether or not it ever had any functional difference is another matter.

    as a side note, $var =& new object(); and $var = &new object(); are equivalent statements (as would be $var=&new object(); - because of how PHP parses whitespace).
    i'd say the former is how it "should be" ("should have been"?) done, and the latter (from your script) is an oddity.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •