I'm working a project and i didn't solve that problem.
I have that function, everything okey but when i run this code i take "Fatal error: Uncaught Error: Object of class Modul could not be converted to string in" error. What can i do for this problem ?
function gelenBelgeleriAl()
{
$result = array();
try
{
$client = new SoapClient($this->servis_url);
$client->__setSoapHeaders($this->soapHeader($this->kullanici_adi,$this->sifre));
$sonuc = $client->gelenBelgeleriAl (
array('vergiTcKimlikNo'=>'1111111',
'belgeTuru'=> 'FATURA',
'parametreler'=>array(
'vergiTcKimlikNo'=>'1111111',
'sonAlinanBelgeSiraNumarasi'=>'0',
'belgeTuru'=> 'FATURA',
'erpKodu'=>"$this->$erp_kodu",
)
)
);
$result['status']="success";
$result['result']=$sonuc->return;
}
catch(Exception $e)
{
$result['status']="error";
$result['error_messsage']=$e->getMessage();
}
return $result;
}
}
$modul = new Modul();
?>
<pre>
<?php
print_r($modul->gelenBelgeleriAl())
?>
</pre>
I don't have a idea how can i solve, thanks for help everyone.
Related
I have code that I am trying to update to work with at least PHP version 7.3 and even when I put in a try catch statement I still get a fatal error thrown.
Below is the function that puts Objects into the Session. line causing error: $objects[$i] = $Object;
function findObjectsLIB() {
$objects = ""; $i = 0;
foreach ($_SESSION['Objects'] as $o => $Object) {
$className = get_class($Object);
if (!empty($className)) {
try {
$objects[$i] = $Object;
$i++;
} catch(Exception $err) {
$_SESSION['errors'] .= $err->getMessage();
}
}
}
return $objects;
}
I am getting this error.
PHP Recoverable fatal error: Object of class Extra could not be
converted to string.
How it not being caught?
For one it is strange that it is not being caught and why is it having an issue in 7.3 but not 5.6?
I'm trying to consume a soap web service using nusoap and PHP 5.6.25 but I am having some errors. Here is the php code:
require_once 'nusoap-0.9.5/lib/nusoap.php';
$client = new nusoap_client('http://www.webservicex.net/ConvertTemperature.asmx?WSDL');
if($client->getError()){
echo 'Error';
} else {
echo 'nusoap is working';
}
Error:
Fatal error: Call to undefined function nusoap_client()
If you check any example on the internet about nusoap_client you can see that it looks like this:
$client = new nusoap_client("food.wsdl", true);
$error = $client->getError();
So when you create a new instances of class nusoap_client you need to add the word new before. So your code will look like this:
$client = new nusoap_client('http://www.webservicex.net/ConvertTemperature.asmx?WSDL');
if($client->getError()){
echo 'Error';
} else {
echo 'nusoap is working';
}
My code snippet is below - as you can see, I have a try-catch block, but inspite of this, I still get an uncaught exception that terminates the entire application. What am I missing?
try {
$cakeXml = simplexml_load_string($xml);
$parseSuccess = $cakeXml->xpath('//ParseSuccess');
} catch (Exception $ex) {
$response['parseSuccess'] = false;
$response['errors']['ParseError'] = 'An unknown error occurred while trying to parse the file. Please try again';
return $response;
}
2014-12-16 22:45:12 Error: Fatal Error (1): Call to a member function xpath() on a non-object
2014-12-16 22:45:12 Error: [FatalErrorException] Call to a member function xpath() on a non-object
If you read the error message more-carefully, you will see that it is not dieing on an Exception, but on a Fatal Error. A try/catch statement cannot catch a fatal error in PHP, as there is no way to recover from a fatal error.
As for solving this issue, your error is telling you $cakeXml is a non-object. One solution would be to do something like this.
try {
$cakeXml = simplexml_load_string($xml);
if (!is_object($cakeXml)) {
throw new Exception('simplexml_load_string returned non-object');
}
$parseSuccess = $cakeXml->xpath('//ParseSuccess');
} catch (Exception $ex) {
$response['parseSuccess'] = false;
$response['errors']['ParseError'] = 'An unknown error occurred while trying to parse the file. Please try again';
return $response;
}
DOMXPath methods i.e. xpath or evaluate does not throw exceptions. Hence, you will need to explicitly validate and throw the exception.
See below code snippet:
$xml_1= "";
try {
$cakeXml = simplexml_load_string($xml_1);
if ( !is_object($cakeXml) ) {
throw new Exception(sprintf('Not an object (Object: %s)', var_export($cakeXml, true)));
} else {
$parseSuccess = $cakeXml->xpath('//pages');
print('<pre>');print_r($parseSuccess);
}
} catch (Exception $ex) {
echo 'Caught exception: ', $ex->getMessage(), "\n";
}
I am trying to use exception handling in case a file does not exists. For example when I run the model method and pass a string usr (which I know there is no file with that name) . It gives me the following error message
Fatal error: Uncaught exception 'Exception' with message 'Usr.php was not found' in /app/core/controller.php on line 14
I can't figure out whats wrong here. Can someone please help me figure this out?
Below is my code. Thanks alot!
class Controllers{
public function model($model){
if(!file_exists("../app/models/".$model.".php")) {
throw new exception("{$model}.php was not found");
}
try {
require ("../app/models/".$model.".php");
} catch(Exception $e) {
echo $e->getMessage();
}
return new $model();
}
}
You can't throw an exception without catching it; this automatically causes the PHP script to crash. So, you need to surround your entire function in the try-catch block, or the "model not found" exception will be uncaught. Your code should be something like this:
<?php
class Controllers {
public function model($model){
try {
if (!file_exists("../app/models/".$model.".php")) {
throw new Exception("{$model}.php was not found");
}
require ("../app/models/".$model.".php");
} catch(Exception $e) {
echo $e->getMessage();
}
return new $model();
}
}
Never mind guys! I found out I needed to use the try/catch blocks in the file where my method is being invoked
Example..
class Home extends Controllers{
public function index($name = ""){
try{
$user = $this->model('Usr');
}catch (Exception $e){
echo $e->getMessage();
}
//var_dump($user);
}
I'm getting the following error:
Catchable fatal error: Object of class stdClass could not be converted to string
I am using php5.5.34.
My code is as follows:
<?php
if($queryaddress_select_user_basic_info = $db->query("SELECT * FROM user_basic_info WHERE username = '$valusername_registerphp'"))
{
if($count = $queryaddress_select_user_basic_info->num_rows)
{
while($valuesinloop_userbasicinfo = $queryaddress_select_user_basic_info->fetch_object())
{
echo $valuesinloop_userbasicinfo->username,'<br>';
echo $_SESSION['user_primaryvalue'] =$valuesinloop_userbasicinfo; //error is on this line
}
}
else
{
echo "cannot count results/cannot return results";
}
}
else
{
echo "query not written correctly!";
}
?>
Any ideas why it's throwing an error?
$valuesinloop_userbasicinfo is an object. You're setting the value of a session to that object (which works fine) but do mind that setting a variable will also return its value.
echo $_SESSION['user_primaryvalue'] =$valuesinloop_userbasicinfo;
This line will not only set the value of $_SESSION['user_primaryvalue'] but also echo it and considering $_SESSION['user_primaryvalue'] is now an object it will cause the given error.