This is a part of SpreadsheetReader_XLSX.php from spreadsheet-reader-master that I want to use on PHP 5.2.6 but it always gives an error: Fatal error: Call to undefined method DateTime::add() in ..\spreadsheet-reader-master\SpreadsheetReader_XLSX.php on line 830 and it is not possible to upgrate my PHP version.
$Value = clone self::$BaseDate;
$Value -> add(new DateInterval('P'.$Days.'D'.($Seconds ? 'T'.$Seconds.'S' : '')));
if (!$this -> Options['ReturnDateTimeObjects'])
{
$Value = $Value -> format($Format['Code']);
}
else
{
// A DateTime object is returned
}
Related
I try to used to an old customized module in my Prestashop that runs with php 7.0.
I got an error and no idea...
Fatal error: Uncaught Error: Call to undefined method Product::getFrontFeaturesHiddenByNameStatic()
And here is the line of code.
$feature = Product::getFrontFeaturesHiddenByNameStatic((int)($params['cookie']->id_lang), $product['id_product'],'_Descriptif accueil');
And that function is defined in "override" folder.
public static function getFrontFeaturesHiddenByNameStatic($id_lang, $id_product, $featureName) {
self::getFrontFeaturesStatic($id_lang, $id_product);
if( isset(self::$_frontFeaturesCacheHidden[$id_product.'-'.$id_lang]) )
foreach(self::$_frontFeaturesCacheHidden[$id_product.'-'.$id_lang] as $feature) {
if( $featureName == $feature["name"] )
return $feature;
}
return null; // nothing has been found
}
Thanks in advance !
I think I found the solution.
Actually the override definition was not in the right folder.
It was in override/classes and failed, while set in modules/mymodule/override/classes, it seems to work fine...
Thank for your help!
I have this script
$prefix = "feed_";
$keys = #$memcached->getAllKeys();
foreach ($keys as $index => $key) {
if (strpos($key,$prefix) !== 0) {
unset($keys[$index]);
} else {
$memcached->delete($key);
}
}
that return this fatal error: Fatal error: Uncaught Error: Call to undefined method stdClass::getAllKeys().
If I run PHP5.* all works fine. But with PHP7.* it's not the same.
I don't find anything about deprecated function http://php.net/manual/en/memcached.getallkeys.php
How can I resolve this problem?
So, I am working on a project and I am having an issue as I keep getting both errors and warnings. I am quite new to PHP so be gentle. The program runs fine using PHP 5.5 However when I run the program in PHP 5.6 I receive several errors as follows;
[10-Oct-2016 10:04:46 America/Denver] PHP Warning: Erroneous data format for unserializing 'MMR\Bundle\CodeTyperBundle\Entity\User' in /hermes/bosnaweb14a/b1234/.../application/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 833
[10-Oct-2016 10:04:46 America/Denver] PHP Notice: unserialize(): Error at offset 49 of 50 bytes in /hermes/bosnaweb14a/b1234/.../application/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 833
[10-Oct-2016 10:04:46 America/Denver] PHP Fatal error: __clone method called on non-object in /hermes/bosnaweb14a/b1234/.../application/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 837
Project Info
Platform: Symfony
PHP Version: 5.6
Affected Code
public function newInstance()
{
if ($this->_prototype === null) {
if (PHP_VERSION_ID === 50429 || PHP_VERSION_ID === 50513) {
$this->_prototype = $this->reflClass->newInstanceWithoutConstructor();
} else {
$this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name)); //Line 833
}
}
return clone $this->_prototype; //Line 837
}
Any help would be greatly appreciated
I tested:
var_dump(clone $t=unserialize(sprintf('O:%d:"%s":0:{}', strlen('name'), 'name')));
And it works.
You have to check the value of $this->name maybe its empty or has illegal chars.
Where is $this->name set in the first place?
Quick Fix:
just add one more version i.e: PHP 5.6 for your if condition and it will be PHP_VERSION_ID === 50640 in your if condition
like:
if ($this->_prototype === null) {
if (PHP_VERSION_ID === 50429 || PHP_VERSION_ID === 50513 || PHP_VERSION_ID === 50640) {
$this->_prototype = $this->reflClass>newInstanceWithoutConstructor();
} else {
$this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
}
}
The code is
// Get singleton (first value from row with single value)
static function singleton($arg, $params = false) {
return pg_fetch_row(SQL($arg, $params))[0];
}
The error message is
2014-02-19 12:54:23: (mod_fastcgi.c.2701) FastCGI-stderr: PHP message: PHP Parse error: syntax error, unexpected '[' in /var/www/blockexplorer.com/htdocs/includes/sql.inc on line 69
I think there is a config that can fix it.
This depends on PHP version you are using. If you are using PHP 5.4 or above then your code will not give error otherwise you will have to store the result in a variable and use it.
Reference : PHP 5.4
Look for "Array Dereferencing" here.
Put the result of the function in a variable
static function singleton($arg, $params = false) {
$foo = pg_fetch_row(SQL($arg, $params));
return $foo[0];
}
PHP does not support anonymous arrays. Use an named array instead:
static function singleton($arg, $params = false) {
$row=pg_fetch_row(SQL($arg, $params));
return $row[0];
}
I'm using PHP 5.3.6 and when I try to run the code bellow I get the following error: "
Fatal error: Call to a member function format() on a non-object in ...".
function diferenta_date($data_inceput, $data_sfarsit){
$interval = date_diff(date_create($data_inceput), date_create($data_sfarsit));
$output = $interval->format("Years:%Y,Months:%M,Days:%d,Hours:%H,Minutes:%i,Seconds:%s");
$return_output = array();
array_walk(explode(',', $output), function($val, $key) use(&$return_output) {
$v = explode(':', $val);
$return_output[$v[0]] = $v[1];
});
return $return_output;
}
What's wrong?
You need to check the return values. The documentation says date_diff() returns:
The DateInterval object representing the difference between the two dates or FALSE on failure.
date_diff() is failing and you are trying to use FALSE as an object.