$resp = new stdClass();
$resp->first_name->type = "select";
$resp->first_name->required = 'true';
$resp->first_name->type_meta->options[0] = "opt 1";
$resp->first_name->type_meta->options[1] = "opt 2";
$resp->first_name->type_meta->options[2] = "opt 3";
$resp->last_name->type = "text";
$resp->last_name->required = 'true';
$resp->last_name->type_meta=new stdClass();
Why does my script won't work on my php file but works on w3schools php try it compiler. The error I get is
Fatal error: Uncaught Error: Attempt to assign property "type" on null
Even though I am using stdClass() to create an object so why it gives null for type field.
You need to create the sub-properties first. A property without a value is null, so you need to make it an stdClass as well and then you can go.
$resp = new stdClass();
$resp->first_name = new stdClass();
$resp->first_name->type = "select";
$resp->first_name->required = 'true';
$resp->first_name->type_meta = new stdClass();
$resp->first_name->type_meta->options[0] = "opt 1";
$resp->first_name->type_meta->options[1] = "opt 2";
$resp->first_name->type_meta->options[2] = "opt 3";
$resp->last_name = new stdClass();
$resp->last_name->type = "text";
$resp->last_name->required = 'true';
$resp->last_name->type_meta=new stdClass();
you need to set a value for $resp->first_name and $resp->last_name because there values is null or if you are using php 8 you can use null safer operator like this : $resp->first_name?->type = "select";
Related
I have the following code running on PHP 7.4.2, but after the update to PHP 8.1.2, I'm getting an error in order to fill an array with some data.
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$myObj->status = '1';
$myObj->video = $row["token"];
$title = str_replace(".mp4","",$row["filename"]);
$myObj->title = $title;
I'm getting the following error:
Fatal error: Uncaught Error: Attempt to assign property "status" on null
Is this problem related to some change in PHP 8? I've tried to find some answers but have no success on how I can update the code to run in this new scenario.
You need to create $myObj before you can assign to $myObj->status.
while($row = $result->fetch_assoc()) {
$myObj = new StdClass;
$myObj->status = '1';
$myObj->video = $row["token"];
$title = str_replace(".mp4","",$row["filename"]);
$myObj->title = $title;
You are using a object of class without declaring it before which means that you need to tell PHP by declaring it outside the while loop.
class YourClassName{
public $status;
public $video;
public $title;
}
$myObj = new YourClassName;
while($row = $result->fetch_assoc()) {
$myObj = new StdClass;
$myObj->status = '1';
$myObj->video = $row["token"];
$title = str_replace(".mp4","",$row["filename"]);
$myObj->title = $title;
}
When sending data to the SomeMethod() method, the 1 excess parameter returns as an error.
My Code:
$client = new SoapClient('site_url/?wsdl');
$client->soap_defencoding = 'UTF-8';
$loginparam = array('userName'=>'name','password'=>'pass','trace' => 1, 'exceptions' => 0);
$session = $client->OturumAc($loginparam);
$SoapIcHeader = new SoapHeader("http://sanayi.gov.tr","TokenId",$session->OturumAcResult);
$client->__setSoapHeaders($SoapIcHeader);
$OturumUzat = $client->OturumDogrulaVeUzat($session ->OturumAcResult);
$param["BosAgirligi"] = "20";
$param["CalismaBasinci"] = "5";
$param["DoluAgirligi"] = "1";
$param["SonMuayeneTarihi"] = "2017-08-01 10:19:04";
$param["SonMuayeneYapanFirmaMersisNo"] = "123456789";
$param["SuKapasitesi"] = "1";
$param["TestBasinci"] = "10";
$param["DolumBasinci"] = "15";
$param["EtKalinligi"] = "3";
$param["ImalatTarihi"] = "2017-08-01 10:19:04";
$param["SeriNo"] = "123";
$param["TescilEdenTesisId"] = "31fd684c-f97d-48c1-a7fb-60f30f536d8d";
$param["UreticiId"] = "31fd684c-f97d-48c1-a7fb-60f30f536d8d";
// $param["UygunlukIsareti"] = "1";
$date = date('d/m/Y');
$id ="2ad9a9a9-adb9-4fb8-8fae-01e84aa72343";
try
{
$sonuc = $client->TupTescil($id,$date,$param);
print_r($sonuc);
}
catch (Exception $e)
{
echo "Error ! ";
echo $e -> getMessage ();
}
Return Error
Error ! The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'TupTescil'. End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 281.
This example works with C#
Guid tupKimligi = new Guid("07FAF194-4E80-4359-95D9-011CA1F5A1D4");
DateTime islemSaati = DateTime.Today;
TupTescilBilgisi tescilBilgileri = new TupTescilBilgisi()
{
BosAgirligi = 1,
CalismaBasinci = 1,
DoluAgirligi = 1,
SonMuayeneTarihi = DateTime.Today,
SonMuayeneYapanFirmaMersisNo = "123456789",
SuKapasitesi = 1,
TestBasinci = 1,
DolumBasinci = 1,
EtKalinligi = 1,
ImalatTarihi = DateTime.Today,
SeriNo = "123",
TescilEdenTesisId = tesisId,
UreticiId = ureticiId,
UygunlukIsareti = TupUygunlukIsareti.Pi
};
Tup tescilSonuc = tsc.TupTescil(tupKimligi, DateTime.Today, tescilBilgileri);
You can also look at the wsdl structure here
enter link description here
Thanks for your help
I'm trying to create an update with Laravel 5.1 but it shows the error:
I have 2 updates in this method and I noticed that the error already happens in the first one
Type error: Argument 1 passed to
Illuminate\Database\Eloquent\Builder::update() must be of the type
array, null given
My Controller
public function update($id)
{
$dadosForm = $this->request->except('_token');
$dadosForm = $this->request->offsetUnset('fat_cnpj');
$dadosForm = $this->request->offsetUnset('vatendimento');
$dadosForm = $this->request->offsetUnset('integra');
$dadosForm = $this->request->offsetUnset('material');
$proposta = $this->proposta;
$proposta->cliente_id = $this->request->get('cliente_id');
$proposta->contato = $this->request->get('contato');
$proposta->email = $this->request->get('email');
$proposta->telefone = $this->request->get('telefone');
$proposta->fatcnpj = $this->request->get('fatcnpj');
$proposta->atendimento = $this->request->get('atendimento');
$proposta->dt_solicitacao = $this->request->get('dt_solicitacao');
$proposta->dt_vigencia = $this->request->get('dt_vigencia');
$proposta->vendedor = $this->request->get('vendedor');
$proposta->coleta = $this->request->get('coleta');
$proposta->dt_integracao = $this->request->get('dt_integracao');
$proposta->hr_integracao = $this->request->get('hr_integracao');
$proposta->frete_material = $this->request->get('frete_material');
$proposta->status_id = $this->request->get('status_id');
$this->proposta->where('id', $id)->update($dadosForm);
$proposta_id = $id;
$count = $this->ensaios->max('id');
for($i=1;$i<=$count;$i++){ //Save Ensaios
$proposta_ensaios = new PropostaEnsaios();
$proposta_ensaios->id_proposta = $proposta_id;
$proposta_ensaios->id_produto = $i;
$proposta_ensaios->quantidade = $dadosForm['quantidade_'.$i];
$proposta_ensaios->valor= $dadosForm['valor_'.$i];
$proposta_ensaios->total = $dadosForm['total_'.$i];
$proposta_ensaios->where('id', $id)->update($dadosForm);
}
$this->request->session()->flash('alert-success', 'Dados Alterados com Sucesso!');
return redirect()->route('manage-content');
}
You're setting the $dadosForm variable to NULL in the last four lines of:
$dadosForm = $this->request->except('_token');
$dadosForm = $this->request->offsetUnset('fat_cnpj');
$dadosForm = $this->request->offsetUnset('vatendimento');
$dadosForm = $this->request->offsetUnset('integra');
$dadosForm = $this->request->offsetUnset('material');
(For reference PHP will return a NULL value from functions which don't specify a return - as offsetUnset doesn't.) I believe you're intending to do something more like:
$this->request->offsetUnset('fat_cnpj');
$this->request->offsetUnset('vatendimento');
$this->request->offsetUnset('integra');
$this->request->offsetUnset('material');
$dadosForm = $this->request->except('_token');
I am trying to use SoapClient in PHP to retrieve data from a WSDL. If I use hardcoded values, then it works with zero errors:
$client = new SoapClient(someWSDLUrl);
$params2 = array();
$params2['AuthenticationKey'] = $obj->{'LoginResult'};
$params2['VehicleClass'] = 'UsedCar';
$params2['ApplicationCategory'] = 'Consumer';
$params2['VersionDate'] = '2016';
$result2 = $client->GetMakes($params2);
I am getting the following error when I use variables or dynamic content:
Fatal error: Uncaught SoapFault exception: [a:DeserializationFailed
] The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter
http://someURL/VehicleInformationService:VehicleClass
. The InnerException message was 'Invalid enum value 'UsedCars'
I have tried
$client = new SoapClient(someWSDLUrl);
$params2 = array();
$params2['AuthenticationKey'] = $obj->{'LoginResult'};
$params2['VehicleClass'] = $VehicleClass;
$params2['ApplicationCategory'] = $ApplicationCategory;
$params2['VersionDate'] = $VersionDate;
$result2 = $client->GetMakes($params2);
I have also tried
$client = new SoapClient(someWSDLUrl);
$params2 = array();
$params2['AuthenticationKey'] = (string) $obj->{'LoginResult'};
$params2['VehicleClass'] = (string) $VehicleClass;
$params2['ApplicationCategory'] = (string) $ApplicationCategory;
$params2['VersionDate'] = (string) $VersionDate;
$result2 = $client->GetMakes($params2);
I have also tried:
$SubmitData = new stdClass();
$SubmitData->AuthenticationKey = new SoapVar($obj->{'LoginResult'}, XSD_STRING);
$SubmitData->VehicleClass = new SoapVar($VehicleClass, XSD_STRING);
$SubmitData->ApplicationCategory = new SoapVar($ApplicationCategory, XSD_STRING);
$SubmitData->VersionDate = new SoapVar($VersionDate, XSD_STRING);
$result2 = $client->GetMakes($SubmitData);
Same error each time. I do not know how to get around "Invalid enum value" error
Thanks in advance
The following coding sample doesn't work.
$joiner = new Entity();
$joiner->name = $post['name'];
$joiner->address = $post['address'];
$meeting = Meeting::first($_id);
$meeting->joiner[] = $joiner;
$meeting->save();
I hope each time when the form posted success. a new joiner entity should be pushed into the 'joiner' property of meeting object.
How to correct it ? and thanks for all help.
updated
now I have changed it like this .it works fine but still not very good yet.
$joiner = new Entity();
$joiner->name = $post['name'];
$joiner->address = $post['address'];
$meeting = Meeting::first($_id);
if(empty($meeting->joiner)){
$joiners = array($joiner);
}
else{
$joiners = array();
foreach($meeting->joiner as $one){
$joiners[] = $one;
}
$joiners[] = $joiner;
}
$meeting->joiner = $joiners;
$meeting->save();