I have a date time object which I would like to modify the microseconds. I'm using the following code.
$datesArray[$alreadyDoneIndices+$countIndices]->modify("+$microsecondIncrementAmount mseconds");
and I'm getting the following error message.
DateTime::modify() [datetime.modify]: Failed to parse time string (+38462 microseconds) at position 3 (4): Unexpected character in C:\xampp\htdocs\DynamicUpdating\timelineUpdater.php on line 147
What's not working with this? Is there a reference for what relative timestamps work in php that I'm missing if that is the problem?
Just check mseconds in modify("+$microsecondIncrementAmount mseconds") The error message tells you that the time string is wrong.
$datesArray[$alreadyDoneIndices+$countIndices]->modify("+{$microsecondIncrementAmount} mseconds");
Notice the {}
Related
I need to get a file from SharePoint using phpSPO.
I use this code:
$authCtx = new AuthenticationContext('https://xxxxxxxx.sharepoint.com');
$authCtx->acquireTokenForUser($username,$password);
$ctx = new ClientContext('https://xxxxxxxx.sharepoint.com/sites',$authCtx);
require('settings.php');
$sourceFileUrl = "/path/to/excel.xlsx";
$targetPath = "/files/excel.xlsx";
$fileContent = Office365\SharePoint\File::openBinary($ctx, $sourceFileUrl);
But I get this error:
Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/www.mydomain.dk/vendor/vgrem/php-spo/src/Runtime/Http/Requests.php on line 137
Isn't phpSPO ready for php 8.0 or what could be wrong?
A deprecation is not an error. It's a hint to the author of the code that they will need to fix the code "soon" (i.e. within the next few years, when PHP 9.0 is expected to ship) so that it doesn't become an error.
If you want to identify what needs changing and contribute a fix, I'm sure the maintainer will appreciate the help.
If not, it is perfectly safe to completely ignore the message. If necessary, change your error configuration to ignore deprecations, or to ignore them within the "vendor" directory where third-party code lives, using something similar to this answer.
I'm redoing a large portion of my website to use older mysql_* extensions because they execute faster. Yes I know people say its not a good idea to use older extensions, but I need to go for speed since this code is part of the back-end operations to my website and I want to serve as many people as possible.
I do have a small issue after converting things over. Sometimes when I try to close a database connection I get a PHP warning of:
PHP Warning: mysql_close(): 33 is not a valid MySQL-Link resource in /path/to/script.php on line #
and the line refers to the code below:
function DBclose($c){
if (isset($c) && !mysql_close($c)){
error_log("DB handle is invalid/null. Called from ".debug_backtrace()[2]['function'].'->'.debug_backtrace()[1]['function']);
}
}
This only happens sometimes.
What I want to do is change only this warning so that it includes the function that called it. Maybe to something more like:
PHP Warning: mysql_close(): 33 is not a valid MySQL-Link resource in /path/to/script.php on line # called from parent function <function-name>
How do I fix this and still make it so that other function calls I make that begin with # will have no errors printed on screen?
I don't think you can change the message, however, you can check if it's a resource using is_resource()
I needed to change the data_scale of a decimal field implemented by the module "computed field".
I changed the field_data_MYFIELD directly in database (from 10,2 to 10,4).
I also modified the field_revision_MYFIELD the same way.
As third step, I modified the data of the field_config by changing:
FROM
s:14:"data_precision";s:2:"10";s:10:"data_scale";s:1:"2";
TO
s:14:"data_precision";s:2:"10";s:10:"data_scale";s:1:"4";
As I'm trying to clear caches with drush cc all, I get the following error:
PHP Fatal error: Unsupported operand types in
DRUPAL_SITE/modules/field/field.info.class.inc on line 495
The line 495 is:
// Make sure all expected field settings are present.
$field['settings'] += field_info_field_settings($field['type']);
I enabled the error log in index.php and have the following errors:
unserialize(): Error at offset 330 of 1314 bytes in DRUPAL_SITE/modules/field/field.crud.inc on line 374
Notice: Undefined index: settings in DRUPAL_SITE/sites/all/modules/computed_field/computed_field.install on line 13
Undefined index: settings in DRUPAL_SITE/modules/field/field.info.class.inc on line 495
Fatal error: Unsupported operand types in DRUPAL_SITE/modules/field/field.info.class.inc on line 495
What am I doing wrong?
Never a good idea to alter settings via mysql directly, take a look here to do it from code : https://drupal.stackexchange.com/questions/79378/changing-a-field-type-from-integer-to-decimal/151367#151367
Instead, you could have use an hook_update to alter the field.
Thank you Clive. I did'nt paste the whole data ...apologize. The data_precision etc keys are indeed inside a database key within that string. I tested the data content into http://blog.tanist.co.uk/files/unserialize/ (as suggested) and the string is not valid ... you were right. I fixed it by changing different values of the S lenght in order to match the content of each S . After some tests, the problem is now resolved. It appears that editing the Blob data (for computed fields with php code inside) directly from phpmyadmin is not a good idea as far as it adds many additional char that doesn't match the lenght of the S. Thanks again for your help.
When doing merge cells and applying style in loop script is giving fatal error mentioned below.
Fatal error: Maximum execution time of 30 seconds exceeded in D:\xampp\htdocs\bookings\vendor\phpoffice\phpexcel\Classes\PHPExcel\Cell.php on line 892
NOTE: but if we use it out side the loop it works fine, My code which i use to apply style and merge the cell is as below.
$range = chr($alpha).'1:'.chr($alpha+1).'1';
$spreadsheetWriter->mergeCell($range);
$spreadsheetWriter->setCellStyle($range);
What is wrong here, or is there any way which i can use to handle fatal error.
Thanks
Amit
I keep getting an error on this code:
<?php
function encode_object(&$obj) {
foreach ($obj as &$current) {
if (is_string($current) or is_object($current) or is_array($current)) {
if (is_object($current) or is_array($current)) {
encode_object($current);
}
if (is_string($current)) {
$current = urlencode($current);
}
}
}
}
?>
This code has worked before but for some reason every time a run it I get:
Fatal error: Maximum execution time of 30 seconds exceeded in * on line 9
What I'm trying to do is be able to give it an object, search through it and encode all of the strings.
I have tried multiple times but keep getting the same error
I am using:
Apache 2.2.15.0
PHP 5.3.3
Windows 7 Ultimate build 7600
EDIT:
The input I'm entering is an error that, after going through this function, is meant to be converted into JSON and read by javascript through ajax.
The input in this case would be:
array("error"=>
array(
"error"=>"error",
"number"=>2,
"message=>"json_encode() [<a href='function.json-encode'>function.json-encode<\/a>]: recursion detected",
"line"=>22))
That is another error that i will worry about later, but it seems that when I put
$obj['error']['message'] = 'blah';
on the object before I send it, the code works fine. So there is something about
json_encode() [<a href='function.json-encode'>function.json-encode<\/a>]: recursion detected
that urlencode seems to be having a problem with.
If it has worked before, then it seems there's nothing wrong with the code, just that the objects you're sending it are large and are taking longer to process than the default execution time set in PHP.
The quick and dirty way to handle this is to use the ini_set() function:
ini_set("max_execution_time",840); (in this case, 840 is 840/60 or 14 minutes)
I've used this before on a query with a particularly large result-set, one which took at minimum five minutes to load, and build the HTML for the page.
Note, this will not work if your host has "Safe Mode" enabled. In that case you actually have to change the setting in PHP.ini. Otherwise, I use this quick and dirty roundabout fairly often for ridiculously huge parsing/processing tasks.