Ansego Posted June 15, 2014 Share Posted June 15, 2014 Hello, I am having some troubles and was hoping someone could guide me through it. Q: When ever I try call my get_status function all I get is a white page of nothing, no errors to work from etc... Can anyone here see what I am doing wrong? PATH: index.php NOTICE //<<-- KILLS PAGE <?php spl_autoload_register(function ($class) { include '/lib/' . $class . '.inc'; }); $servers = new servers; echo $servers->get_servers(); echo "STATUS: ".$servers->get_status("0.0.0.0",80); //<<-- KILLS PAGE ?> Page works fine until I want to use the status function, I get no errors or anything just a blank page. PATH: Lib/Servers.inc NOTICE //<<-- KILLS PAGE <?php ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(E_ALL); error_reporting(-1); include_once '../../Global-Includes/ServerStatus/db-connect.php'; //namespace xStatus; class servers { private $db_Hostname = HOSTNAME; private $db_Username = USERNAME; private $db_Password = PASSWORD; private $db_Database = DATABASE; private $dbSQL = ''; function __construct() { } // End Construct public function get_servers(){ $db = new mysqli($this->db_Hostname,$this->db_Username,$this->db_Password,$this->db_Database); $message = ''; // list current servers from database $sql = "SELECT * FROM tbl_servers"; $res = $db->query($sql); if ($res->num_rows > 0) { $message = '<h3>Current Servers</h3>'; while ($row = $res->fetch_assoc()) { $message .= $row['HostGame'] . '<br>'; $message .= $row['HostIP'] . '<br>'; $message .= $row['HostPort'] . '<br>'; $message .= $this->get_status($row['HostIP'],$row['HostPort']) . '<br>'; //<<-- KILLS PAGE! } } $message .= "<br>End of the \"Server List\" "; return $message; } public function get_status(&$ServerIP,&$ServerPort){ if(@stream_socket_client("tcp://".$this.$ServerIP.":".$this.$ServerPort."", $errno, $errstr, 1) !== false) { return "Online"; } else { return "Offline"; } return "Offline"; } } // End class ?> Kind regards and thank you. Quote Link to comment https://forums.phpfreaks.com/topic/289162-white-page-no-error-calling-function-in-class/ Share on other sites More sharing options...
Ch0cu3r Posted June 15, 2014 Share Posted June 15, 2014 First try moving your error reporting code to index.php Also paths beginning with a / mean it will load the file from the root of the hard drive, not the sites root (were you domain points to). Quote Link to comment https://forums.phpfreaks.com/topic/289162-white-page-no-error-calling-function-in-class/#findComment-1482687 Share on other sites More sharing options...
Ansego Posted June 15, 2014 Author Share Posted June 15, 2014 Hi Ch0cu3r. I've moved the error reporting code to index.php with no change to outcome, still white page. <?php ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(E_ALL); error_reporting(-1); ?> I have removed the / from the include but still no change, white page no data. include 'lib/' . $class . '.inc'; Quote Link to comment https://forums.phpfreaks.com/topic/289162-white-page-no-error-calling-function-in-class/#findComment-1482688 Share on other sites More sharing options...
Solution Ch0cu3r Posted June 15, 2014 Solution Share Posted June 15, 2014 (edited) Ok looking further at your code. Here public function get_status(&$ServerIP,&$ServerPort){ You have defined the ServerIP and ServerPort arguments can only be passed by reference (this is what the & means before the variable name). Because of this you cannot pass a hardcoded value (such as string or integer) when calling the method. You can however call it like this $ip = "0.0.0.0"; $port = 80; /* on calling this method $ip and $port will be passed by reference */ echo "STATUS: ".$servers->get_status($ip , $port); Next remove $this. from in front of the variables on this line (why are you concatenating the object here?). And remove the error suppression operator ( @ ) too. if(@stream_socket_client("tcp://".$this.$ServerIP.":".$this.$ServerPort."", $errno, $errstr, 1) !== false) { Edited June 15, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/289162-white-page-no-error-calling-function-in-class/#findComment-1482689 Share on other sites More sharing options...
Ansego Posted June 15, 2014 Author Share Posted June 15, 2014 Hi Ch0cu3r, Well done mate, I removed the ( @ ) and ( & ) and gave me an error: Catchable fatal error: Object of class servers could not be converted to string in.... Which pointed too: if(stream_socket_client("tcp://".$this.$ServerIP.":".$this.$ServerPort."", $errno, $errstr, 1) !== false) { I removed $this and wrapped it with "" and it works great now. End result: if(stream_socket_client("tcp://$ServerIP:$ServerPort", $errno, $errstr, 1) !== false) { Giving that reference page you have posted a good read too, cheers. Thanks mate, your awesome! Quote Link to comment https://forums.phpfreaks.com/topic/289162-white-page-no-error-calling-function-in-class/#findComment-1482690 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.