I am troubleshooting an error in PHP and I don't know how to resolve it. I don't have any PHP knowledge.
Here is the code:
function _act($sql) {
if (!$this->_link) {
Fatal::internalError('Tried to make database query before connection.');
}
$r = mysql_query($sql, $this->_link);
if ($r === false) {
Fatal::dbError($sql, "Database query failed", mysql_error());
}
return $r;
}
In the error log I get the following:
[24-Jan-2013 13:25:38 America/Denver] PHP Strict Standards: Non-static method Fatal::dbError() should not be called statically, assuming $this from incompatible context in /home1/flcclear/public_html/Library/classes/Query.php on line 91
I have tried to make it an object call with $r->mysql_error(); but this caused a different error. I am not trying to rewrite this code, just trying to correct the errors for an elementary/middle school which equals no money, volunteer time.
Thanks in advance.
make Fatal::internalError,Fata::dbError (also other methods you are using like "Fatal::methodName") static
example :
class Fatal
{
public static dbError($sql,$message){
//method body
}
}
but the error message is referring to the Fatal::dbError and not to mysql_error.
Fatal::dbError is a class designed for you? Try this:
Class Fatal{
...
static public dbError(...){...}
...
}
Related
i've moved my Kohana 2.3.4 installation to a new hosting with php7 (probably that's a root of the issue) and now i am getting the following error:
Uncaught PHP Error: Non-static method AdminHook::menu_tree() should not be called statically in file system/core/Event.php on line 209
Here's my Event.php around line 209 (call_user_func($callback); is at line 209):
public static function run($name, & $data = NULL)
{
if ( ! empty(self::$events[$name]))
{
// So callbacks can access Event::$data
self::$data =& $data;
$callbacks = self::get($name);
foreach ($callbacks as $callback)
{
call_user_func($callback); // LINE 209
}
// Do this to prevent data from getting 'stuck'
$clear_data = '';
self::$data =& $clear_data;
}
// The event has been run!
self::$has_run[$name] = $name;
}
And here's the AdminHook class:
class AdminHook {
public function menu_tree(){
$session = Session::instance();
if(isset($_GET['_ml']) AND $_GET['_ml'] == 1) {
$session->set('menuLink', 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
//url::redirect(url::current());
}
global $menuLink;
$menuLink = $session->get('menuLink');
}
}
If i set menu_tree function to static, i get the following error:
Uncaught PHP Error: Declaration of Menu_Model::validate(array &$array, $save = false) should be compatible with ORM_Core::validate(Validation $array, $save = false) in file application/models/menu.php on line 18
I've been trying to find a solution for the next couple of days, but can't seem to find one. Any help is highly appreciated!
Errors are not related to each other. By simply setting that method as static, php goes to showing the next error.
You have bad Menu_Model declaration. It mut be compatible with ORM_Core::validate
Menu_Model::validate(/*bad: array & */ Validation $array, $save = false)
This question already has an answer here:
Strict Standards: Non-static method StreamComment::getCommentsHTML() should not be called statically, assuming $this from incompatible context
(1 answer)
Closed 2 years ago.
I have a rudimentary knowledge of PHP, and I am facing an error retrieving a JSON object from my PHP web service
Strict standards: Non-static method API_USERS::getRecordByID() should not be called statically, assuming $this from incompatible context in .../lists.php on line 1387
and thus because of this error I am unable to parse my JSON object properly and get this error in my Android Studio logcat
Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
is there a way I can get rid of this error? This is the PHP I am trying to use:
<?php
define('IEM_PATH', '../admin/com');
require_once('../admin/includes/config.php');
require_once('../admin/com/lib/IEM.class.php');
require_once ('../admin/com/lib/IEM/DBFACTORY.class.php');
require_once ('../admin/com/lib/IEM/baseAPI.class.php');
require_once ('../admin/com/lib/API/USERS.class.php');
require_once ('../admin/com/lib/IEM/baseRecord.class.php');
require_once ('../admin/com/lib/record/Users.class.php');
function GetLists($userid = 0, $getUnconfirmedCount = false) {
$userid = $_REQUEST['userID'];
if (!$userid) {
trigger_error('This user object is not loaded with any user.... You will need to supply the userid as a parameter.', E_USER_NOTICE);
return false;
}
if (!$userid) {
$userid = $this->userid;
}
require_once('../admin/functions/api/lists.php');
$listapi = new Lists_API();
$returnA = $listapi->GetListByUserID($userid, $getUnconfirmedCount);
$returnResult1 = array();
foreach ($returnA as $key => $value) {
//$lists[] = $key;
$returnResult["contactList"][] = array("listID" => $returnA[$key]['listid'], "name" => $returnA[$key]['name']);
}
$returnResult["success"] = 1;
echo json_encode($returnResult);
}
GetLists();
and this is the code which I believe to be the source of error (line 1387)
$user = API_USERS::getRecordById($userid);
This code was copied from a class:
$userid = $this->userid;
You don't have $this when you're not in a (non static) member function.
just delete these 3 lines:
if (!$userid) {
$userid = $this->userid;
}
Your methode getRecordByID() should by declared like this :
public static function getRecordByID() {
...
}
Or You should call it after instanciate the API_USERS class like :
$instance = new API_USERS();
$instance->getRecordByID();
I'm quite new to php and I tested this code on my local server and it was working fine but when I uploaded it to webserver I started getting the following errors.
This is the Code :
"if($stmt=$mysqli->prepare("SELECT members.id, permissions.name FROM members,permissions WHERE username=? AND password=? AND members.type=permissions.id" )){
$username=$input["user"];
$password=$input["pass"];
$configsalt=$config["salt"];
$stmt->bind_param("ss",$username,md5($password.$configsalt));
$stmt->execute();
$stmt->bind_result($id,$type);
$stmt->fetch();"
The line 39 is "$stmt->bind_param("ss",$username,md5($password.$configsalt));"
Strict Standards: Only variables should be passed by reference in
/home/hotel132/public_html/bulbmg/index.php on line 39
Fatal error: Cannot redeclare is_admin() (previously declared in /home/hotel132/public_html/bulbmg/includes/config.php:22) in /home/hotel132/public_html/bulbmg/includes/config.php on line 28
I don't know why the second error is occuring!!!
'
.......
//Functions
function is_admin(){
if($_SESSION['type']=="admin"){
return true;
}
else{
return false;
}
} //line 28
?>'
Kidly help me out with this.
You should not use literals, try using variables.
The error:
Are you including or requiring file(s) more than one time? Try include_once/require_once
Otherwise check function_exists
EDIT:
Have you tried this?
if (!function_exists('is_admin')) {
function is_admin(){
if($_SESSION['type']=="admin")
return true;
else
return false;
}
}
I want to test this method:
Class:
public function bind(\Elastica\ResultSet $result = null) {
if (!$result instanceof \Elastica\ResultSet) {
throw new \InvalidArgumentException('I need an instance of \Elastica\ResultSet');
}
$this->bindedData = $result->getResults();
$this->isBinded = true;
}
Test
public function testGetTransformedDataNotSuccesful() {
$this->object->bind(new \stdClass()); //This throws a Catchable fatal error
}
My question is:
How can i test this?
An alternative is not to Type Hint the method var.
Or shouldn't i test this.
Wouldn't it make sense that PHP throws an exception instead of throwing a fatal error ?
Throwing a fatal error is correct, as your method signature explicitly asks for a \Elastica\ResultSet but you provide an \stdClass.
Removing the typehint would also remove the fatal error - but that doesn't make much sense imho :)
edit
This test should pass
public function testGetTransformedDataNotSuccesful() {
$this->setExpectedException(get_class(new PHPUnit_Framework_Error("",0,"",1)));
$this->object->bind(new \stdClass()); //This throws a Catchable fatal error
}
i want to use this script to do ping without using the exec(); or the commands that similar to it.
the problem is i get these errors:
Strict Standards: Non-static method Net_Ping::factory() should not be
called statically in C:\xampp\htdocs\test.php on line
3
Strict Standards: Non-static method Net_Ping::_setSystemName() should
not be called statically in C:\xampp\php\PEAR\Net\Ping.php on line 141
Strict Standards: Non-static method Net_Ping::_setPingPath() should
not be called statically in C:\xampp\php\PEAR\Net\Ping.php on line 143
Strict Standards: Non-static method PEAR::isError() should not be
called statically in C:\xampp\htdocs\test.php on line
4
the code on test.php
<?php
require_once "Net/Ping.php";
$ping = Net_Ping::factory();
if (PEAR::isError($ping)) {
echo $ping->getMessage();
} else {
$ping->setArgs(array('count' => 2));
var_dump($ping->ping('example.com'));
}
?>
Nothing wrong, the PEAR component is just not fit for E_STRICT. The code you have is okay, but the PEAR code doesn't say the method is static, so PHP will emit an E_STRICT warning. That's not something you can really change, but you can opt to ignore it, by adjusting your error_reporting settings.
<?php
// before PEAR stuff.
$errLevel = error_reporting( E_ALL );
// PEAR stuff.
require_once "Net/Ping.php";
$ping = Net_Ping::factory();
if (PEAR::isError($ping)) {
echo $ping->getMessage();
} else {
$ping->setArgs(array('count' => 2));
$result = $ping->ping('example.com');
}
// restore the original error level.
error_reporting( $errLevel );
var_dump( $result );
Here is a ping class I wrote last year when I needed to do this on a system that didn't have PEAR.
Example usage:
$ping = new ping();
if (!$ping->setHost('google.com')) exit('Could not set host: '.$this->getLastErrorStr());
var_dump($ping->send());