Jump to content

Fatal error experienced after converting to PHP5 from PHP4


jmosher

Recommended Posts

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.
Link to comment
Share on other sites

[quote author=jmosher link=topic=109235.msg440152#msg440152 date=1159057811]
... as $this has been discontinued in version 5 and support is no longer offered.
[/quote]

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.
Link to comment
Share on other sites

[quote]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.[/quote]
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?
Link to comment
Share on other sites

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/bug.php?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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[quote author=Barand link=topic=109235.msg440555#msg440555 date=1159139625]... seems to me to be the programming equivalent of sitting on a branch and sawing it off at the trunk.[/quote]

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

And to fix your problem:

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

output( $this );

unset($this);[/code]

Replace $this with anything.

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

output($result);

unset($result);[/code]

Replace $result with your favorite variable.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.