how to see which line caused warning in PHP - php

I am using a code where code is in code.php and the user defined functions are stored in function.php.
The functions are called multiple times.
While executing the code in code.php - I got the following error message.
Warning: in_array() expects parameter 2 to be array, null given in C:\xampp\htdocs\SanskritVerb\function.php on line 1177
the line 1177 of function.php falls inside a user defined function 'ends'.
How can I know which line of code.php called this function 'ends' ?
I think some languages show error like - Error in line X of function.php called in line Y of code.php
If something of this sort exists for PHP - it would save my debug time.

For such a task you need to assign an error handler and call
Exception::getTrace()
to get trace of Exception. see the documentation set_error_handler.
Using xdebug extension for PHP can give you higher tracing capabilities even without error. If you choose xdebug you should enable tracing by adding lines to php.ini
xdebug.auto_trace=On
xdebug.trace_output_dir=c:\path
Anyway this is up to you.

Related

Wordpress php Plugin not found

I am getting this Warning and my Header and Footer on my Website are not showing them right.
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'remove_admin_bar_style_frontend' not found or invalid function name in /home/toolsebo/www/yr-1007/wp-includes/plugin.php on line 496
I tried to find the remove_admin_bar_style_frontend in my functions.php to remove it but i cant.
Please help me to get this fixed i really don't know how to go ahead.
wp-includes/plugin.php is a core file, it wouldn't be in there, that's just what's generating the error.
Look in your wp-content/themes/your_theme_name/ folder for a functions.php or similar file. The function will be in there.
This means you are calling the function "remove_admin_bar_style_frontend" but that function was not in your plugin or theme. Search for that initiating code block and comment it.Try to search add_action('....

What is this error and How to solve it Missing argument 2 for PLATFORMS::get_device_info()

I am having this error on my wp multi site ,
Warning: Missing argument 2 for PLATFORMS::get_device_info(), called in /homepages/13/d133448570/htdocs/sogolearn/prosper/tracking202/redirect/rtr.php on line 395 and defined in /homepages/13/d133448570/htdocs/sogolearn/prosper/202-config/connect2.php on line 258
Warning: Cannot modify header information - headers already sent by (output started at /homepages/13/d133448570/htdocs/sogolearn/prosper/202-config/connect2.php:258) in /homepages/13/d133448570/htdocs/sogolearn/prosper/tracking202/redirect/rtr.php on line 286
Page url = http://prosper.sogolearn.com/tracking202/redirect/rtr.php?t202id=8368&t202kw=
Rest of the functions are working properly, no errors on the main site or other domains.
I have no idea what is this error and How to fix it.
The first error is caused by only providing one argument to a function or method that requires at least two arguments. For example, if we have a function like this:
function hasTwoArguments($first, $second) {
// Do something...
}
...then the error occurs if it is called like this:
// The second argument is required, but is not provided, causing an error
hasTwoArguments('first');
The second error is most likely a side-effect of the first error. HTTP headers must be set before any output is sent to the client (the browser in this case). The first error outputs a message (describing what went wrong), which is why the second error occurred.
To fix these errors you have to make sure that the PLATFORMS::get_device_info() method gets two arguments. If you have written the code yourself then you can either provide the second argument, or you can make the second argument optional (if it indeed is optional). If you did not write the code yourself then you should contact the author(s) of the code, telling them that they may have made a mistake.

Modx: Catchable fatal error: Argument 2 passed to modParser::collectElementTags() must be of the type array, null given

Just started with new project and want to try ModX to use it for the project but get stuck on this error (it won't disappear) :
**Catchable fatal error: Argument 2 passed to modParser::collectElementTags() must be of the type array, null given, called in D:\Personal\illumation\modx\core\model\modx\modstaticresource.class.php on line 57 and defined in D:\Personal\illumation\modx\core\model\modx\modparser.class.php on line 101**
It went wrong at the moment I want to try to write a plugin so i created a new plugin in the Manager in an external file called webit-core-plugin.php. Add one event to it and save it. After this, the error described above appear.
Tried to remove it, do it again etc, nothing helps. Does anybody know what is going on?
I use the latest XAMPP, latest SQL/PHP and lastest ModX running on localhost (windows 7) with adminstrator privileges.
Clear Cache folder manually by deleting it through file browser
Open your SQL client, check your elements (templates - *modx_site_templates*, chunks - *modx_site_htmlsnippets*, snippets - *modx_site_snippets*, and plugins - *modx_site_plugins*) that have "static" field = 1, but have "static_file" empty.

PHP Include operator can't seem to find php script

I am having an odd problem that continues to baffle me. I appreciate your advice....
In a PHP 5.3 script I am including another PHP script using the following code;
include 'moninit.php?id=1234'; // initialize array variables
moninit.php is stored as C:\xampp\htdocs\CarmelServices\moninit.php
In php.ini the include path is:
include_path = "C:\xampp\htdocs\CarmelServices"
So, the include should execute moninit.php but I get the following error returns;
Warning: include(moninit.php?id=1234) [function.include]: failed to
open stream: No error in C:\xampp\htdocs\CarmelServices\SensorW.php on
line 48
Warning: include() [function.include]: Failed opening
'moninit.php?id=1234' for inclusion
(include_path='C:\xampp\htdocs\CarmelServices') in
C:\xampp\htdocs\CarmelServices\SensorW.php on line 48
If I execute moninit.php directly using a browser, it works fine. So, somehow the include cant seem to find moninit. SensorW is also in the same folder as moninit.
Very odd, at least to me. Thanks!
include does not execute a PHP script; it only inserts the contents of the file into the currently-running script.
In your example, you are telling the PHP interpreter to find and open a file named 'moninit.php?id=1234' which does not exist. You may wish to include 'monit.php' itself or find another way (such as cURL) to execute the script and retrieve the response.
You cannot pass array variables with it, it's included directly in your script and will inherit any variables in the available scope. So you can assign to an array and use that instead.
$data = array('id' => '1234');
include 'moninit.php'; // In moninit.php, use $data instead
If you're just routing the parameters passed, don't worry - they already work.
#GeorgeCummins' answer explains how include() works. Also, you can only pass it the name of the file. You can't pass it variables like you're doing. It's a file name, not a URL.

How do I incorporate the line number of php source code in a custom error message?

I want to do my proper error generator when i'm programming (HTML + PHP).
How can i take the line, when i have an error, and put in a variable?
Example :
echo " Error # 03: variable undefined line #".$line." ";
Thanks.
the variables you'd be looking for are:
__LINE__
__FILE__
__FUNCTION__
__CLASS__
there is a predefined constant, __LINE__ that contains the line where it was actually called.
However, I guess that trigger_error() function perfectly fits "error generator" term, thus being exactly what you're looking for.
It will not only show you a line and a file and a timestamp, but also will follow general behavior of PHP error reporting settings, which is very important - you should never echo errors implicitly but rather put it into standard error stream
for the custom error handler there is also a debug_backtrace() function.
Assuming you are referring to PHP compile time errors and warnings, the line number is automatically displayed. Since these messages are generated at compile time (and as such can cause the script not to execute fully) I would recommend using the default messages rather than using a custom solution.
If PHP is not displaying the error messages, use the following code to display all of the PHP error messages and warnings on a page:
error_reporting(E_ALL);

Categories