How do I define fire_event, undefined fire_event error - php

I'm cleaning up all the errors in an old script and I'm getting one that says undefined function fire_event. How do I define fire_event. everything works fine but i've turned on error_reporting(E_ALL); to fix all hidden errors
Fatal error: Call to undefined function fire_event() in /home/social/public_html/includes/dologin.php on line 96
if (strpos($en['redirect'],'index.php?req=login')) unset($en['redirect']);
$redirect = (isset($en['redirect']) && $en['redirect']!='' ? $en['redirect'] : constant('dir').'members.html');
fire_event('member_login',$line['m_id']);
header('Location: '.$redirect);
exit;
}

That has to be some custom function and we don't know what belongs in there. Search all source files, because you most likely removed or changed a dependency and/or include() or required() line.

Related

PHP buffering error <unknown> in line 0

Would anybody be kind to help me with any possible information on this error? causes? login? where to look/start?
Cannot use output buffering in output buffering display handlers in <**Unknown**> on line **0**
Example code:
function test($b) { return _strrev($b); }
ob_start("test");
echo "123";
ob_end_flush();
Information:
This is CentOS 6.7
This is PHP PHP 5.5.32 (cli)
This is NOT Wordpress
This is a simple PHP file with pseudo code (above)
No caching, no Varnish, no Nginx, no custom headers
Thanks
In an effort to make this question of some use to others I will summarise the comments section in the form of an answer.
It turns out that if you make a coding error in the callback function used by ob_start it generates this somewhat unhelpful error message
In testing I quite accidentally made a silly error while amending the callback funtion shown by the questioner, I coded
<?php
function test($b) {
return str-replace('2', 'XXX', $b);
}
ob_start("test");
echo "123";
ob_end_flush();
Note the misspelling of the str_replace() function.
This generated the error
Fatal error: Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0
So it appears that PHP cannot report runtime errors in an ob_start callback funtion. Instead it must default to a generic error along the lines of Ouch that hurt
Maybe one of us should report this as a PHP Bug
After some more testing, this error senario produces a meaningful error in PHP 7.0.5
Notice: Use of undefined constant str - assumed 'str' in tst.php on line 3
Fatal error: Uncaught Error: Call to undefined function replace() in tst.php:3
so this may be fixed now, but all previous PHP versions i.e. 5.4 / 5.5 / 5.6 produce the unhelpful error message

Undefined variable in IF statement (but seems correctly declared)

Something makes me crazy, I get an Undefined variable if I declare a variable in an IF statement. If I declare this variable above the IF statement, the PHP Notice disapear.
My code :
if($tab_sel==FILENAME_DEFAULT){ // FILENAME_DEFAULT = index.php
if(...){
some functions
}
$nb_pages=ceil($count/$limit) : 0;
}
echo $nb_pages; //4000 is displayed on the page (OK),
but in the Nginx log, I get :
FastCGI sent in stderr: "PHP message: PHP Notice : Undefined variable nb_pages in /.../index.php
but when I load the page, I can see that nb_page is displayed correctly (example: value is 4000), but in the log, undefined variable..
In my example, if I declare nb_pages above "if($tab_sel==FILENAME_DEFAULT){", the undefined disapear.
Any idea?
That's because you're creating the variable inside a if that can fail to pass. In this case, the variable would be undefined and PHP will throw an error since it couldn't find the variable that you are asking for afterwards.
Declare it before the if and you will be just fine.
$nb_pages;
if($tab_sel==FILENAME_DEFAULT){
if(...){
I think it might me an environment issue. Try to put both FILENAME_DEFAULT and $nb_pages into a log file:
file_put_contents(
'test.log',
date('[Y-m-d H:i:s] ')
. FILENAME_DEFAULT . "\t" . #$nb_pages . PHP_EOL,
FILE_APPEND
);
The # will prevent the warning message.
I found why it didn't work :
in case of a 404 error page (called FILENAME_404)
I also use the index.php file in which I call the variables undeclared.
that's why the Nginx error said about index.php, not because it doesn't go into if($tab_sel==FILENAME_DEFAULT){ but because in some other cases I use also index.php with tab_sel=FILENAME_404
thank you everyone!

PHP include call throws warnings but continues

I've got a pretty simple PHP script, but I can't for the life of me work out why one line doesn't work.
The main script:
<?php
include("/includes/processes.php");
?>
[...]
<?php
if(getUserLevel() == 3) {
?>
[...]
processes.php is in the right place and all that. It should be defining getUserLevel(). Here it is:
<?php
function getUserLevel() {
if(isset($_COOKIE["userlvl"]) && isset($_SESSION["userlvl"]) {
if($_COOKIE["userlvl"] == $_SESSION["userlvl"]) return $_SESSION["userlvl"];
else return 0;
}
else {
return 0;
}
}
function usernameIs($name) {
if($_COOKIE["username"] == $name && $_SESSION["username"] == $name) return true;
else return false;
}
?>
So when I go to index.php (the main script), it gives me two warnings and one fatal error:
Warning: include(/includes/processes.php): failed to open stream: No such file or directory in /home/u164546666/public_html/index.php on line 2
Warning: include(): Failed opening '/includes/processes.php' for inclusion (include_path='.:/opt/php-5.5/pear') in /home/u164546666/public_html/index.php on line 2
Fatal error: Call to undefined function getUserLevel() in /home/u164546666/public_html/index.php on line 27
(line 2 is the include() call, line 27 the call to getUserLevel())
It's pretty obvious why I've got the fatal error - because the include() has failed - but why is that? Is it a server config issue or have I just written it wrong?
The file tree:
index.php
/includes
/processes.php
You are probably need the relative path and is missing the .
<?php
include("./includes/processes.php");
?>
Change your include to
include_once dirname(__FILE__) . "/includes/processes.php";
However, I'd go for require as the file includes vital functionality.
require is identical to include except upon failure it will also produce a fatal E_COMPILE_ERROR level error. In other words, it will halt the script whereas include only emits a warning (E_WARNING) which allows the script to continue.
The issue is with your include statement. Just get rid of the parenthesis around that as:
include "/includes/processes.php";

Code in try block continues executing after exception?

I am trying to implement Google+ login on my website and am running into an issue. Here is my code (after creating a Google_Client object):
try {
$client->authenticate($_GET['code']);
$plus = new \Google_Service_Plus($client);
$person = $plus->people->get('me');
$firstName = $person->modelData->name->givenName;
} catch (Google_Auth_Exception $e) {
$response = array(
'error' => 'Error: Authentication exception.'
);
} catch (Exception $e) {
$response = array(
'error' => 'Error: Uncaught exception.'
);
}
$client->authenticate() throws a Google_Auth_Exception if the code passed to it is invalid
If authentication failed, then reading properties from the $person object causes fatal errors
$responseis echo'd out as a JSON-encoded object
The problem is that the try/catch code does not seem to be working properly. When authentication fails due to the code in $_GET['code'] being invalid, the following response is returned from the script:
{"error":"Error: Authentication exception."}
So far so good -- the code in the first catch block was executed.
However, the code in the try block continues to execute in a weird fashion. I say "weird" because in the above form, a bunch of errors (culminating in a fatal error) occur, meaning this line:
$firstName = $person->modelData->name->givenName;
Is still executed! It should not be executed since an exception was thrown on a previous line. If I comment out the above line, the errors are not thrown (again indicating this line is executed, which it shouldn't be).
Here are the errors outputted due to the above line executing after the exception has been thrown:
Notice: Undefined index: modelData in [...]\google-api-php-client-master\src\Google\Model.php on line 78
Notice: Trying to get property of non-object in [...]\ajax_handler.php on line 720 [note: this is the line shown above, where the property is being accessed]
Notice: Trying to get property of non-object in [...]\ajax_handler.php on line 720
Another reason I said "weird" is that if I add this line:
die('dying before reading property');
Right before the above line (where I read a property), no errors occur, BUT the "dying before reading property" text is not output onto the page! This is weird because the script is clearly still executing code in the try block after the error is thrown (since without this die() line, the line reading the property is executed and results in lots of errors being output). As with before, the code in the catch block is still executed and the JSON is output onto the page.
What on earth is going on?
PHP is a compiled language. See this question and this answer for an explanation.
Basically, the code is parsed, assembled, and compiled into bytecode before it's executed; what's happening with your script is that the code is invalid. The syntax is correct, so PHP doesn't just outright fail. The issue arises after the object $person is constructed, when you try to access a dynamic property (modelData) that doesn't exist or is inaccessible due to its scope. So the errors you are seeing are because PHP can't find it.
The reason the code doesn't output 'dying before reading property' is because the code isn't actually being executed, so it can't "stop" execution; it's already stopped.
Change
$firstName = $person->modelData->name->givenName;
to
$firstName = $person->name->givenName;
and you should be good to go.
This question and its selected answer keep bothering me. It seems so unlikely that PHP would have executed/parsed/whatever, while an exception was already thrown.
I would rather suggest the code is being run twice. The first time giving the Exception message, and the second time producing the notices.
I suggest you try this:
put $testVar = uniqid(); just before try {
put echo $testVar; just after try {
When you run the code now you should see a unique ID just before the Exception message, and (my theory) another/different unique ID just before your notices. This would prove the code is being run twice.
About the die("..."); not appearing, I would ask if you really checked this looking in your HTML source, because it could be hidden for some reasong. (eg invisible div)

register_globals off - now I get an odd undefined but it shouldn't be

What I had BEFORE was...
if(DEBUGMODE) $debug_err_msgs[] = 'Some error'; // add a new error to the array
... more code here...
if(DEBUGMODE)$debug_err_msgs[] = 'Some error'; // add a new error to the array
which worked great EXCEPT in functions. SO... I decided to make it GLOBAL by using the $_GLOBALS array. I originally liked the 1st method I chose because it kept adding to the array and I could dump it later on to view what was happening.. Using the $_GLOBALS['debug_err_msgs'] and $_GLOBALS['errorh_string'] is forcing me to .= (append) the string to the previous one (which is ok... I didn't think you could go... $_GLOBALS['something'][] and keep adding to the array like I did before I changed my code. SO.. I made changes as below...
PHP
<?php
error_reporting(E_ALL);
set_error_handler("ErrorHandler");
$_GLOBALS['errorh_string'] = "";
if(DEBUGMODE) $_GLOBALS['debug_err_msgs'] = "";
if(DEBUGMODE) $_GLOBALS['debug_err_msgs'] .= 'La la la, some errors';
if(DEBUGMODE) $_GLOBALS['debug_err_msgs'] .= 'more errors... etc';
function ErrorHandler($errno, $errstr, $errfile, $errline)
{
// if ($errno == 8) return;// 8 is undefined variables
$error = "<b>Error[</b>$errno<b>] </b>$errstr<br />";
$_GLOBALS['errorh_string'] .= $error; // append new error to the global string
return true; // dont execute the php internal error handler
}
?>
ERRORS IM GETTING
Notice: Undefined index: errorh_string in /debugOpenBlock.php on line 14
Notice: Undefined index: errorh_string in /debugOpenBlock.php on line 14
Which in the code above, is INSIDE the function
$_GLOBALS['errorh_string'] .= $error; // GIVES ME UNDEFINED
Here is what's weird... if I change the line to read...
$_GLOBALS['errorh_string'] = $error; // NO ERROR NOW
I even tried
$_GLOBALS['errorh_string'] = $_GLOBALS['errorh_string'] . $error; // GIVES ME UNDEFINED
If 'errorh_string' is a literal? why do I get undefined in it.!?!??! Am I missing something about GLOBALS?
As I was writting this I was thinking I could have used
global $debug_err_msg[]; // make this array global
instead of changing all my code to the way I have it now but... I'm curious what this problem is now... I hate not knowing something :)
BTW - I just recently turned off register_globals in the PHP.INI file. Could this have anything to do with it (note: I NEVER used $_SESSION['somevariable'] as $somevariable (mainly because I didn't know you could do that but... doesn't matter anyways)).
I've read piles of articles about superglobals, register_globals etc but nothing sheds any light on this..
Awaiting wisdom oh greater than I web developers :)
I can't find another problem, so the issue seems that you just used the wrong variable name. It is called $GLOBALS, not $_GLOBALS - unlike the input arrays. (It's not affected by the register_globals setting btw.)
global $debug_err_msg;
You should actually prefer this method. That makes using the variable more legible than with the $GLOBALS[] access, and it also shows that you intentionally share that variable.

Categories