ping with php phar - php

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());

Related

Non-static method should not be called statically in Kohana 2.3.4

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)

Strict standards: Non-static method should not be called statically, assuming $this from incompatible context in php file [duplicate]

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();

Strict Standards: Only variables should be passed by reference

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;
}
}

PHP Strict Standards: Non-static method Fatal::dbError()

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(...){...}
...
}

How to handle erroneous argument type in this situation?

I'd like to use stdClass to store options for some methods, instead of passing huge lists of variables (inspired by javascript-style coding)
However, I'd like to make sure I'm always getting an instance of stdClass as an argument. I know I can add a hint in the argument (gb::search below) but when I deliberately try to break it, I'm not sure how to handle the error.
Any tips?
class gb extends CI_Model {
protected $searchtypes = array('full','partial');
protected $endpoint = "https://local.endpoint";
function __construct() {
parent::__construct();
// sample search
$options = new stdClass();
$options->term = 'sample search';
$options->type = 'full';
$this->search($options);
}
function clean_term($term){
$term = trim($term);
return $term;
}
function search(stdClass $options){
$term = $options->term;
$type = $options->type;
// make sure we're doing a valid search
if (!$term || !in_array($type, $this->searchtypes)) {
return false;
}
$term = $this->clean_term($term); // etc
}
The error it throws is something like:
A PHP Error was encountered
Severity: 4096
Message: Argument 1 passed to gb::search() must be an instance of stdClass, null given, called in /application/models/gb.php on line 20 and defined
Filename: models/gb.php
Line Number: 29
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/gb.php
Line Number: 31
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/gb.php
Line Number: 32
Any ideas how to approach this from a CodeIgniter point of view?
if I remember - mistyped argument should raise E_RECOVERABLE_ERROR, so, it triggers error handler but execution continues. So, you have two options basically.
One is to throw exception in error handler when E_RECOVERABLE_ERROR is encountered. To halt execution.
Another - check type with instanceof stdClass and do what you suppose - raise exception or return something.
UPDATE In your case your framework (CI is for CodeIgniter?) sets error handler (somewhere using set_error_handler). So, after logging or printing error message execution continues. (If there was not handler you would get fatal error). Just test type of argument manually:
function search(stdClass $options){
// test type for sure, because of recoverable error
if (!($options instanceof stdClass)) {
return false; // or throw new InvalidArgumentException('Parameter should be instance of stdClass');
}
$term = $options->term;
$type = $options->type;
// make sure we're doing a valid search
if (!$term || !in_array($type, $this->searchtypes)) {
return false;
}
$term = $this->clean_term($term); // etc
}

Categories