Jump to content


Photo

Fatal error experienced after converting to PHP5 from PHP4


  • Please log in to reply
12 replies to this topic

#1 jmosher

jmosher
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 24 September 2006 - 12:30 AM

I'm hoping someone might be able to help me out with this issue. I converted to PHP5 from PHP4 and found there are new stricter methods to handle calls and queries.

When I try to logon to my system to access my database I receive the following error:

Fatal error: Call to undefined method stdClass::setPageContent() in /usr/share/calltracker/includes/functions.php on line 402

Here is the code specific to that section in functions.php:

400 # First set the page content array entry
401
402 $result->setPageContent();
403
404 # Get the page navigation function
405
406 $result->parameters["SMALL_NAV"] = admin_page_navigation();
407 $result->parameters["NAV_TREE"] = admin_page_navigation("tree");
408 $result->parameters["USER_NAVBAR"] = user_page_navigation();
409 $result->parameters["VERSION"] = EP_VERSION;
410 $result->parameters["SCRIPT_NAME"] = EP_SCRIPT_NAME;
411 $result->parameters["COPYRIGHT"] = COPYRIGHT;
412 $result->parameters["NUMQUERIES"] = count($db->queries);
413
414 # Set the template to the configured value
415
416 if($result->template == "") { $result->template = $CONF['template']; }
417
418 if($result->no_cache == 1)
419 {
420 $result->html = $GLOBALS['reg'];
421 }
422 else
423 {
424 # Import the template code
425
426 $result->html = implode(file($result->template),"");
427 }
428
429 # Replace every tag in the template
430 # with its entry in the parameters
431 # array
432
433 foreach($result->parameters as $key => $value)
434 {
435
436 $result->tag = '{' . "$key" . '}';
437
438 if($key != "PAGE_CONTENT")
439 {
440 $result->html = str_replace($result->tag,$value,$result->html);
441 }
442
443 }
444
445 $result->html = str_replace("{PAGE_CONTENT}", $result->parameters["PAGE_CONTENT"], $result->html);
446
447 # Output the created HTML code
448
449 echo($result->html);
450
451 }
452
453 # This function will set a value in the parameters
454 # array
455
456 function setParameter($name,$value) {
457
458 $result->parameters[$name] = $value;
459
460 }
461
462 # This concludes the template object
463
464 }

No problems are experienced when using PHP4.3.x

Note**: The variable $result has replaced the accepted variable function $this as $this has been discontinued in version 5 and support is no longer offered.

Thanks for any help offered.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 24 September 2006 - 01:22 AM

... as $this has been discontinued in version 5 and support is no longer offered.


And there's me using $this with version 5 classes with no problems. They obviously forgot to to include me in the circulation list when that memo went out.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 24 September 2006 - 05:45 PM

Note**: The variable $result has replaced the accepted variable function $this as $this has been discontinued in version 5 and support is no longer offered.

Huh! I agree with Barand here. $this has not been discontinued from PHP5. If it has the documentation would reflect this and my OO programmed scripts will fail work. Where did you get that from?

#4 jmosher

jmosher
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 24 September 2006 - 11:02 PM

Hi Guys,

What I did was roll back as per your notion support for $this has not been dropped and this is the original error received:

Fatal error: Cannot re-assign $this in /usr/share/calltracker/includes/functions.php on line 964

Here is the code snippet for the function having a problem.

946 //--------------------------------------------------------+
    947 // Admin table heading output                            |
    948 //--------------------------------------------------------+
    949
    950 function admin_table_heading( $title="" ) {
    951
    952        global $template, $CONF;
    953
    954        //--------------------------------
    955        // If this has not yet been loaded,
    956        // load it and cache it.
    957
    958        if(!isset($GLOBALS['table_header_html']))
    959        #{
    960                #$lines = implode( file("../includes/admin_skins/".$CONF['admin_template']."/table-heading.inc"), "");
    961                #$GLOBALS['table_header_html'] = $lines;
    962        #}
    963
    964        $this = str_replace("{TITLE}", $title, $GLOBALS['table_header_html']);
    965
    966        output( $this );
    967
    968        unset($this);
    969
    970          output( "<table width=100% cellpadding=0 cellspacing=0 style=\"border-bottom: 1px solid #1B95CE\">
    971                <tr><td width=20><img src=../images/general/table-topleft.jpg></td>
    972                    <td background=../images/general/table-toptile.jpg height=21><table width=100%
    973                cellpadding=0 cellspacing=0><tr><td><font color=white><b> " . $title . "</b></font></td></tr></table></td><td width=20><img src=../im        ages/general/table-topright.jpg></td>
    974                </tr>");
    975
    976 }

The original error I posted was produced following these changes -

Updating $this to $result as per this php page indicating that the $this variable was an undocumented feature that was never to be supported and officially dropped in version 5:
http://bugs.php.net/...id=27659&edit=1

Setting these functions to array functions, which are now required based on the way php5 parses the information.
585c585
<              mysql_close($this->connection);
---
>              @mysql_close($result->connection);
591c591
<              return mysql_insert_id();
---
>              return @mysql_insert_id();
602c602
<              return mysql_error();
---
>              return @mysql_error();

So now I'm at the original start point with no applied changes and I'm hoping you could help.

Thanks
--
Jerry

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 24 September 2006 - 11:13 PM

As $this refers to the current object, you can hardly be surprised when it objects to being reassigned as a string variable in

964        $this = str_replace("{TITLE}", $title, $GLOBALS['table_header_html']);

Even trying to assign another object to $this seems to me to be the programming equivalent of sitting on a branch and sawing it off at the trunk.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 jmosher

jmosher
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 25 September 2006 - 12:06 AM

How would you suggest it be corrected?

#7 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 25 September 2006 - 12:46 AM

... seems to me to be the programming equivalent of sitting on a branch and sawing it off at the trunk.


Several cheers for great analogies. Hipy papy bthuthdth thuthda bthuthdy!

And to fix your problem:

Lines 964 to 968
$this = str_replace("{TITLE}", $title, $GLOBALS['table_header_html']);

output( $this );

unset($this);

Replace $this with anything.

$result = str_replace("{TITLE}", $title, $GLOBALS['table_header_html']);

output($result);

unset($result);

Replace $result with your favorite variable.
http://nealylitalo.net - My personal website, and home of The Netizen's Journal.

#8 jmosher

jmosher
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 25 September 2006 - 12:55 AM

I'll give that a shot.  Do I still need to set the @ function in front of the variables I mentioned previously.



#9 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 September 2006 - 02:22 AM

The error supreser should IMO be avoided where possible. However, if you have your own error handling in place, sometimes it can come in handy.

#10 jmosher

jmosher
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 25 September 2006 - 03:02 AM

BTW it worked well.

Would you explain a bit more so I can be humbled by your ever growing GOD complex.

#11 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 September 2006 - 03:19 AM

What are you insinuating by such a comment? I thought I put my last response in pretty clear straight forward terms.

Surely.. if you've written the code you've posted your aware of what the error supersor (@) is and does. And, one would also assume that if your using classes you should have the ability to create your own error handling / trapping. If this isn't your code youve posted, then Im sorry, but you gave the impression you knew what you where talking about.

#12 jmosher

jmosher
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 25 September 2006 - 10:32 AM

You have a great day.

I knew someone had a GOD complex.
---------------

#13 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 25 September 2006 - 10:43 AM

Have you got a question or what?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users