I have the following code in my laravel controller file.
$j_decode->$data['_kfdTourDate']->available = ($j_decode->$data['_kfdTourDate']->available+$totalincrement);
and I am getting the following error.
ErrorException in BookingsController.php line 325: Array to string
conversion in BookingsController.php line 325 at
HandleExceptions->handleError('8', 'Array to string conversion',
'D:\XAMPP\htdocs\lara\app\Http\Controllers\BookingsController.php',
'325', array('request' => object(Request), 'id' => '0', 'rules' =>
array(), 'validator' => object(Validator), 'data' => array('_kpnID' =>
'153290', '_kfnTourID' => '2', '_kfdTourDate' => '2017-03-16',
'nAdults' => '2', 'nChildren' => '1', 'nInfants' => '0', 'nBabies' =>
'2', 'nFOC' => '2', 'nPriceAdult' => '74.25', 'nPriceChild' => '49.5',
'nPriceInfant' => '0', 'nPriceBaby' => '0', 'nTotalPrice' => '148.5',
'tGuestName' => 'Yuhiko Nishioka', 'tGuestOrigin' => 'Unknown',
'tEnquirySourceWhat' => 'Unknown', 'tStatus' => 'Confirmed',
'_kfnAgentID' => '0', '_kfnPersonID' => '0', '_kfnInvoiceID' => '0',
'nAgentCommissionPercent' => '0', 'nDiscount_percent' => '0',
'nDiscount_fixed' => '0', 'tNotes' => '4WD Tour package/Rezdy, applied
discount', 'tInitials' => 'JD', 'CreatedOn' => '2017-01-21 15:08:00',
'ModifiedOn' => '2017-01-21 15:10:00', 'tTicketNumber' => 'Rezdy',
'_kfnOrganisationID' => '0'), 'schedule' => object(Collection),
'j_decode' => object(stdClass), 'update_id_data' => object(stdClass),
'totalincrement' => '3')) in BookingsController.php line 325
Interesting part that it's working on the linux server when I upload it to my host. I have PHP Version 7.0.13 on localhost and PHP Version 5.6.30 on the server.
How can this line cause an Array to string conversion error?
I am not willing to downgrade my php version on localhost as I have other codes that php5 is not supporting.
The whole code in controller:
$rules = $this->validateForm();
$validator = Validator::make($request->all(), $rules);
if ($validator->passes()) {
$data = $this->validatePost( $request );
$schedule = DB::table('schedule')
->where('id','=',$data['_kfnTourID'])
->get();
if(isset($_SESSION['bookingiddata']))
{
print_r ($j_decode= json_decode($schedule[0]->data));
$update_id_data = json_decode($_SESSION['bookingiddata']);
$totalincrement = $update_id_data->nAdults+$update_id_data->nChildren+$update_id_data->nInfants+$update_id_data->nFOC;
//$j_decode->$data['_kfdTourDate']->available = ($j_decode->$data['_kfdTourDate']->available+$totalincrement);
$j_decode->$data['_kfdTourDate']['available'] = ($j_decode->$data['_kfdTourDate']['available']+$totalincrement);
($j_decode->$data)['_kfdTourDate']->status = "available";
Also print_r $j_encode = json_encode($j_decode); prints me the following
{"2017-02-13":{"available":1,"bind":0,"info":"","notes":"","price":0,"promo":0,"status":"available"},"2017-02-14":{"available":1,"bind":0,"info":"","notes":"","price":0,"promo":0,"status":"available"},"2017-02-08":{"available":0,"bind":0,"info":"","notes":"","price":0,"promo":0,"status":"booked"},"2017-02-12":{"available":0,"bind":0,"info":"","notes":"","price":0,"promo":0,"status":"booked"},"2017-02-10":{"available":0,"bind":0,"info":"","notes":"","price":0,"promo":0,"status":"booked"},"2017-02-15":{"available":0,"bind":0,"info":"","notes":"","price":0,"promo":0,"status":"booked"},"2017-02-16":{"available":0,"bind":0,"info":"","notes":"","price":0,"promo":0,"status":"booked"}...
well, as mentioned here
in php 5.6.3 , it's allowed to use this expression:
echo $json_decode->$data['_kfdTourDate']->available;
so , you are trying to access the value of $data['_kfdTourDate'] which is element in $json_decode object
for example: https://3v4l.org/i9Q7p
in php 7,
Indirect access to variables, properties, and methods will now be
evaluated strictly in left-to-right order, as opposed to the previous
mix of special cases. The table below shows how the order of
evaluation has changed.
so, the interpreter will interpret this code as follow:
echo $json_decode->$data['_kfdTourDate']->available;
// first , give me the value $json_decode->$data,
// then choose the _kfdTourDate key
and to solve this, you need to :
echo $json_decode->{$data['_kfdTourDate']}->available;
to tell php that $data['_kfdTourDate'] is just a value;
There were some order-of-operations changes in PHP7 (see Changes to the handling of indirect variables, properties, and methods). I suspect you might need to mess around with some parentheses within $j_decode->$data['_kfdTourDate']->available to make it evaluate in the order you want.
Related
I'm trying to use phpseclib ASN1.php and i have a map like below;
$IdentityObjectMap = array('type' =>FILE_ASN1_TYPE_SEQUENCE,
'children'=> array(
'identityIdentificationData' => array('type'=>FILE_ASN1_TYPE_SEQUENCE,
'children'=> array(
'version' => array('type' => FILE_ASN1_TYPE_IA5_STRING),
'staticData' =>array('type' => FILE_ASN1_TYPE_SEQUENCE,
'children'=> array(
'acceptedPolicyVersion' => array('type' =>FILE_ASN1_TYPE_IA5_STRING),
'cardHolderID' => array('type' =>FILE_ASN1_TYPE_INTEGER),
'deviceSerialNumber' => array('type' => FILE_ASN1_TYPE_SEQUENCE,
'children'=> array(
'deviceType' => array('type' =>FILE_ASN1_TYPE_INTEGER),
'deviceUniqueID' => array('type' =>FILE_ASN1_TYPE_OCTET_STRING)
),
),
'appLabel' => array('type' =>FILE_ASN1_TYPE_UTF8_STRING),
'requestorRole' => array('type' => FILE_ASN1_TYPE_ENUMERATED,
'roleClient'=> array('mapping' =>0),
'roleParticipant' =>array('mapping' =>1)
),
'creationTime' => array('type' =>FILE_ASN1_TYPE_UTC_TIME)
)
)
)
)
)
);
And i have a json and using json_decode(IdentityObject,true) for this map like below;
json:
{
\"identityIdentificationData\":{
\"version\":\"2.0\",
\"staticData\":{
\"acceptedPolicyVersion\":\"2\",
\"cardHolderID\":11111111111,
\"deviceSerialNumber\":{
\"deviceType\":3,
\"deviceUniqueID\":\"11111111\"
},
\"appLabel\":\"examination\",
\"requestorRole\": \"roleClient\",
\"creationTime\": \"180319141236Z\"
}
}
}";
And this jsons output array :
array
'identityIdentificationData' =>
array
'version' => '2.0'
'staticData' =>
array
'acceptedPolicyVersion' => '2'
'cardHolderID' => 11111111111
'deviceSerialNumber' =>
array
'deviceType' => 3
'deviceUniqueID' => '11111111'
'appLabel' => 'examination'
'requestorRole' => 'roleClient'
'creationTime' => '180319141236Z'
What structure this array should be to i can successfully compile.
Final code which gives this error
Undefined index: children .../ASN1.php on line 950.
Final code:
$asn1->encodeDER($IdentityObject,$IdentityObjectMap);
In File/X509.php there's only one enumerated type and it' defined thusly:
$this->CRLReason = array('type' => FILE_ASN1_TYPE_ENUMERATED,
'mapping' => array(
'unspecified',
'keyCompromise',
'cACompromise',
'affiliationChanged',
'superseded',
'cessationOfOperation',
'certificateHold',
// Value 7 is not used.
8 => 'removeFromCRL',
'privilegeWithdrawn',
'aACompromise'
)
);
Your enumerated type definition doesn't include a mapping key. That's probably what you need. eg.
'requestorRole' => array('type' => FILE_ASN1_TYPE_ENUMERATED,
'mapping' => array(
'roleClient',
'roleParticipant'
)
),
That said, what version of phpseclib are you using? I tried your code with 1.0.10 (I think) and got a different error than the one you reported:
Fatal error: Uncaught Error: Call to a member function toBytes() on string
When I used my alternatively defined requestorRole definition I got this error message:
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (180319141236Z) at position 11 (6)
I was able to fix that last error by replacing 'creationTime' => '180319141236Z' with 'creationTime': 'January 1, 2018'. 180319141236Z is closer to the format that X.509 certs use but phpseclib generates that value itself after running it through DateTime or strtotime (per https://github.com/phpseclib/phpseclib/blob/1.0.10/phpseclib/File/X509.php#L3420) and then formatting it appropriately. If you wanted to set it directly, yourself, check this out:
https://github.com/phpseclib/phpseclib/blob/1.0.10/phpseclib/File/X509.php#L3952
Here's my code:
https://pastebin.com/cmmSf6S6
I am new to the Laravel. I have not tried this in browser I am using tests for this.
I have test that looks like this:
public function testStoreRequestValid()
{
$data = [
'name' => 'New Item',
'parameter.count' => '3',
'parameter.0.parameter_id' => '4',
'parameter.0.value_id' => '',
'parameter.0.value' => 'text',
'parameter.1.parameter_id' => '1',
'parameter.1.value_id' => '2',
'parameter.1.value' => 'Yes',
'parameter.2.parameter_id' => '2',
'parameter.2.value_id' => '',
'parameter.2.value' => '10'
];
$response = $this->call('post', '/item', $data);
// ...
}
When I try to fetch data using:
$parameterCount = $request->input('parameter.count');
I get null value (if I use has method it gets false).
When I have tried to use square brackets I have got the results, but I want the API to be usable with JSON too without too much hastle in the JS.
How do I solve this in the most clean way?
Dot in Laravel has a special meaning so you can't really use arrays which have dots in their keys. You should declare your data as follows:
<?php
$data = [];
array_set($data,'name','New Item');
array_set($data,'parameter.count','3');
array_set($data,'parameter.0.parameter_id','4');
array_set($data,'parameter.0.value_id','');
array_set($data,'parameter.0.value','text');
array_set($data,'parameter.1.parameter_id','1');
array_set($data,'parameter.1.value_id','2');
array_set($data,'parameter.1.value','Yes');
array_set($data,'parameter.2.parameter_id','2');
array_set($data,'parameter.2.value_id','');
array_set($data,'parameter.2.value','10');
Learning Laravel and when trying to use a factory on the command line i get this error:
PHP warning: preg_replace(): Parameter mismatch, pattern is a string while replacement is an array in /Applications/MAMP/htdocs/breedr-laravel/vendor/laravel/framework/src/Illuminate/Support/helpers.php on line 671
The factory code is this:
$factory->define(App\Gecko::class, function (Faker\Generator $faker) {
return [
'name' => $faker->name,
'aquisition_date' => $faker->date($format = 'Y-m-d', $max = 'now'),
'morph' => $faker->word,
'sex' => $faker->word,
'genetics' => $faker->word,
'bio' => $faker->paragraphs(3),
'bred' => $faker->numberBetween(0, 1),
'hatchling' => $faker->numberBetween(0, 1),
'clutch' => $faker->randomDigitNotNull,
'image' => 'image.jpg',
'user_id' => $faker->randomDigitNotNull,
];
});
When I run $gecko = factory('App\Gecko')->make(); it loads on the terminal no problem, but when I run $gecko = factory('App\Gecko')->create(); I just get the error above.
I'm very new to this and don't understand what the problem is. If i've missed important code please let me know!
Okay so it's a really simple fix. I just needed to change:
'bio' => $faker->paragraphs(3),
to
'bio' => $faker->paragraphs(3, true),
And now it works absolutely fine :)
I created this array of objects:
$ad_1 = new AdUnit(array('id' => '1', 'name' => 'Ad_1', 'description' => 'great ad', 'code' => 'alpha', 'widget_id' => '123'));
$ad_2 = new AdUnit(array('id' => '2', 'name' => 'Ad_2', 'description' => 'good ad', 'code' => 'delta', 'widget_id' => '456'));
$ad_3 = new AdUnit(array('id' => '3', 'name' => 'Ad_3', 'description' => 'bad ad', 'code' => 'sigma', 'widget_id' => '789'));
$adUnitArr = array($ad_1, $ad_2, $ad_3);
and i want to check that a random ad i got from a function exists in the array. the code to get the ad looks like this:
$fixture = new AdGroup();
$fixture->setAds($adUnitArr);
$randad = $fixture->getRandomAd();
now i want to check if the array contains the random ad i received, what i was able to do like this:
$this->assertEquals(in_array($randad, $adUnitArr), 1); //check if ad in array
but my question is, is there an assert or some other way to check this thing better than the way i did it?? i tried using assertArrayHasKey but i got the following error:
PHPUnit_Framework_Exception: Argument #1 (No Value) of PHPUnit_Framework_Assert::assertArrayHasKey() must be a integer or string
any idea please? thx
Try the assertContains method:
$this->assertContains( $randad, $adUnitArr );
I need to launch a .bat file that creates a php file, containing this text:
<?php
$_mail_mailSpooler = array (
'classname' => 'mail_mailSpooler',
'from' => 'test#test.com',
'array_indirizzi_mail' =>
array (
0 => ‘lol#hotmail.com’,
'testo_mail' => ‘prova’,
'filename_html' => NULL,
'oggetto_mail' => ‘prova’,
'elenco_allegati' => '',
'forza_mail_txt' => 0,
'asl_logger' => '',
'log_identifier' => NULL,
'log_in_web' => 0,
'log_str' => '',
'nome_file_dump' => '../mailSpooler/mail_incoming/maildda2.php',
);
I have tried echo " (test)" >gnagna.php
but it doen't work.
any suggestion please?
thanks
use type instead of echo - echo's only supposed to give user feedback, file reading and writing is properly done by type. Have a look at http://www.robvanderwoude.com/allhelpw2ksp4_en.php#TYPE for more
sorry, but i'm not already able to launch my php with right code.
i've tried type <?php
$_mail_mailSpooler = array (
'classname' => 'mail_mailSpooler',
'from' => 'test#test.com',
'array_indirizzi_mail' =>
array (
0 => ‘lol#hotmail.com’,
'testo_mail' => ‘prova’,
'filename_html' => NULL,
'oggetto_mail' => ‘prova’,
'elenco_allegati' => '',
'forza_mail_txt' => 0,
'asl_logger' => '',
'log_identifier' => NULL,
'log_in_web' => 0,
'log_str' => '',
'nome_file_dump' => '../mailSpooler/mail_incoming/maildda2.php',
); C:\>test.php
but it doesn't work.
moreover your link says that this command displays the content of an existing file and i need to create a new one!