Upgrading from PHP 7.4 to 8.0 bool/null errors - php

I have managed to fix one problem (found answer on google search) but this one still appears on my site:
Warning: Trying to access array offset on value of type bool in /usr/home/.../template-series.php on line 103
Warning: Trying to access array offset on value of type null in /usr/home/.../template-series.php on line 103
Warning: Trying to access array offset on value of type bool in /usr/home/.../template-series.php on line 105
Warning: Trying to access array offset on value of type null in /usr/home/.../template-series.php on line 105
if ($choice == 'choice1') {
$img1 = get_sub_field('series2_rep_img1');
LINE 103: $thumb1 = $img1['sizes']['foundation-small'];
$img2 = get_sub_field('series2_rep_img2');
LINE 105: $thumb2 = $img2['sizes']['foundation-small'];
I would appreciate any help.
Thank you

Related

Error In Wordpress On All Pages Just Below The Header (Using Theme elumine)

The error is in below lines of the addressed file below (Line 186 & 187):
Website (Live): www.healthyminds.world
Tried restoring an earlier back-up(24 hours back), but that didn't work also.
Line 186 & 187 from source line:
$collections = get_option('google_typography_collections');
$google_fonts_all = $this->get_fonts();
$import_fonts = array();
if ($collections) {
foreach ($collections as $collection) {
$font_family = $collection['font_family'];
$font_index = array_search($font_family,
array_column($google_fonts_all,'family'));//Line 186
$font_variants = implode(',', $google_fonts_all[$font_index ['variants']); //Line 187
array_push(
$import_fonts,
array(
'font_family' => $collection['font_family'],
'font_variant' => $font_variants,
Error Messages (On All Pages Of Website, these are just few of the lines):
content/themes/elumine/includes/integrations/google-typography/google-typography.php on line 186
Warning: array_search() expects parameter 2 to be array, null given in /home/customer/www/healthyminds.world/public_html/wp-content/themes/elumine/includes/integrations/google-typography/google-typography.php on line 186
Warning: Illegal string offset 'variants' in /home/customer/www/healthyminds.world/public_html/wp-content/themes/elumine/includes/integrations/google-typography/google-typography.php on line 187
Warning: implode(): Invalid arguments passed in /home/customer/www/healthyminds.world/public_html/wp-content/themes/elumine/includes/integrations/google-typography/google-typography.php on line 187
You are getting the errors because on line 186 the $google_fonts_all either does not contain an array with 'family' key or it is not an array. In either case the expression, array_column($google_fonts_all, 'family'), returns empty.
You can extract the later expression into a variable:
$family = array_column((array)$google_fonts_all, 'family');
On the line 187, check for the isset( $google_fonts_all[$font_index]['variants'] ) either in a conditional statement or itenary.
Regards
Eliasu
Wisdom Labs has posted a patch to fix the problem.

I want to add x customers on Prestashop via code but with extra fields

I'm trying to add customers with a code but the PrestaShop is giving me a bug.
I'm using PHP and XML
$XMLRQString = '<?xml version="1.0" encoding="utf-8"?>'.
'<x:Winmax4GetEntitiesRQ xmlns:x="urn:Winmax4GetEntitiesRQ">'.
'</x:Winmax4GetEntitiesRQ >';
$Params=array(
'CompanyCode'=>'',
'UserLogin'=>'',
'UserPassword'=>'',
'Winmax4GetEntitiesRQXML'=> $XMLRQString
);
$return = $client->GetEntities($Params);
$XMLRSString = new SimpleXMLElement($return->GetEntitiesResult);
foreach ($XMLRSString->Entities->Entity as $entity)
{
$default_lang= Configuration::get('PS_LANG_DEFAULT');
$customer=new Customer();
$customer->email= $entity->Email;
$customer->lastname= $entity->EntityType;
$customer->firstname= [$default_lang => $entity->Name];
$customer->contribuinte= $entity->TaxPayerID;
$customer->passwd= $entity->TaxPayerID;
$customer->active = 1;
$customer->add();
}
ERROR: (1/1) ContextErrorException Warning: preg_match() expects
parameter 2 to be string, array given
in Validate.php line 172
at ValidateCore::isCustomerName(array(object(SimpleXMLElement))) in
ObjectModel.php line 1149
at ObjectModelCore->validateField('firstname',
array(object(SimpleXMLElement))) in ObjectModel.php line 981
at ObjectModelCore->validateFields() in ObjectModel.php line 284
at ObjectModelCore->getFields() in ObjectModel.php line 551
at ObjectModelCore->add(true, true) in Customer.php line 264
at CustomerCore->add() in create_clients.php line 66
When storing values from SimpleXML, if you just refer to the element itself by it's tag name - this will be an instance of SimpleXMLElement. As you want the actual content of the element, the simplest way to do this is to cast it to a string...
$customer->firstname= (string)$entity->Name;

Need advice to make php server side Datatables work properly

There's something weird going on with server-side Datatables from this: https://github.com/n1crack/Datatables.
Don't understand what's going on, i do exactly the same thing as the examples but it simply doesn't work. According to the "where" example https://github.com/n1crack/Datatables/blob/master/public/examples/where/ajax.php, look how simple it should be:
$dt = new Datatables(new MySQL($config));
$dt->query("Select film_id as fid, title, description from film where film_id > 47 and film_id < 83");
echo $dt->generate();
My code:
$config = [ 'host' => 'localhost',
'port' => '3306',
'username' => 'root',
'password' => '',
'database' => 'sys_db_gincana' ];
$dt = new Datatables( new MySQL($config) );
$dt->query("
SELECT seen, id, name, cep, date_format(created,'%d/%m/%Y %h:%i:%s') as created
FROM user
");
echo $dt->generate();
Now look at what my js console prints from my ajax:
A PHP Error was encountered
Severity: 4096 Message: Argument 1 passed to
PHPSQLParser\builders\WhereBuilder::build() must be of the type array,
boolean given, called in C:\Program Files
(x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\gincana\vendor\greenlion\php-sql-parser\src\PHPSQLParser\builders\SelectStatementBuilder.php
on line 74 and defined Filename: builders/WhereBuilder.php
Line Number: 112
A PHP Error was encountered
Severity: Warning Message: Invalid argument supplied for
foreach() Filename: builders/WhereBuilder.php Line
Number: 114
A PHP Error was encountered
Severity: 4096 Message: Argument 1 passed to
PHPSQLParser\builders\WhereBuilder::build() must be of the type array,
boolean given, called in C:\Program Files
(x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\gincana\vendor\greenlion\php-sql-parser\src\PHPSQLParser\builders\SelectStatementBuilder.php
on line 74 and defined Filename: builders/WhereBuilder.php
Line Number: 112
A PHP Error was encountered
Severity: Warning Message: Invalid argument supplied for
foreach() Filename: builders/WhereBuilder.php Line
Number: 114
Fatal error: Call to a member function
fetch_assoc() on a non-object in C:\Program Files
(x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\gincana\vendor\ozdemir\datatables\src\DB\MySQL.php
on line 40
And if if i change the query to:
$dt = new Datatables( new MySQL($config) );
$dt->query("
SELECT seen, id, name, cep, date_format(created,'%d/%m/%Y %h:%i:%s') as created
FROM user
WHERE approved = 0 and canceled = 0
");
echo $dt->generate();
the error changes:
A PHP Error was encountered
Severity: Warning Message: array_merge(): Argument #2 is
not an array Filename: src/Datatables.php Line Number:
47
Fatal error: Call to a member function
fetch_assoc() on a non-object in C:\Program Files
(x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\gincana\vendor\ozdemir\datatables\src\DB\MySQL.php
on line 40
Well, the library is a bit new (january 2015), i wonder if someone that had success using it could help me.
Regards
The problem in the WhereBuilder comes from the PHPSQLParser, can you test the latest version from https://github.com/greenlion/PHP-SQL-Parser? It seems to be a simple SQL statement, so actually it should work. I have moved your issue to GitHub, please follow the changes there.

Unable to fetch Price

I am trying to fetch price from a online store.
Here i am using this code..
<?php
function getPrice($site){
$html = file_get_contents($site);
$dom = new DOMDocument();
$dom->loadHTML($html);
$contents = $dom->document.getElementsByTagName("span");
$price = "";
for($i = 0; $i < $contents->length; $i++){
$content= $contents->item($i);
if($content->getAttribute('class') == "fk-font-verybig pprice vmiddle fk-bold"){
$price = $content->getAttribute('value');
}
}
echo $price;
}
$website = "http://www.flipkart.com/sogo-ss-5365-750-w-pop-up-toaster/p/itmdz3hgfjzgfp4v?pid=PUTDYWT2UHPCDCG8&offer=DOTDOnPopUpToaster_Sep2.&icmpid=hp_dotd_3_DOTDOnPopUpToaster_Sep2.";
getPrice($website);
?>
my script return error
Warning: DOMDocument::loadHTML(): Unexpected end tag : span in Entity, line: 261 in E:\Local server\htdocs\store\scripts\getprice.php on line 5
Warning: DOMDocument::loadHTML(): htmlParseEntityRef: no name in Entity, line: 293 in E:\Local server\htdocs\store\scripts\getprice.php on line 5
...................................................................
Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 6160 in E:\Local server\htdocs\store\scripts\getprice.php on line 5
Notice: Undefined property: DOMDocument::$document in E:\Local server\htdocs\store\scripts\getprice.php on line 6
Fatal error: Call to undefined function getElementsByTagName() in E:\Local server\htdocs\store\scripts\getprice.php on line 6
Is it ok to fetch price like this because the store keep changing price of its product.
Is there any other alternative way to do so?
Will this script affect my server performance because ever time user visit a product page on my website it will fetch prices from 5 different stores to comapare prices.
$contents = $dom->document.getElementsByTagName("span");
Your $dom->document is failing because DOMDocument class does not have a property named 'document'.
Notice: Undefined property: DOMDocument::$document in E:\Local server\htdocs\store\scripts\getprice.php on line 6
So this might work
$contents = $dom->getElementsByTagName("span");
The above should work.
I recommend iterating over $contents instead of echo.
Even print_r would help you see the structure of the nodes in $contents.

php/ xml Test is xml contains element

can you test if an xml file has a specific element. I tried this below:
$restrict = ($xml_content->xpath('//app:control//yt:state'));
$name = $restrict[0][0];
$restrictTest = $name->attributes();
if ($restrictTest == "restricted"){
$_SESSION['array']['restricted'] = 1;
}
but it displays this error:
Warning: SimpleXMLElement::xpath() [simplexmlelement.xpath]: Undefined namespace prefix in C:\xampp\htdocs\ytm\resources\func.php on line 178
Warning: SimpleXMLElement::xpath() [simplexmlelement.xpath]: xmlXPathEval: evaluation failed in C:\xampp\htdocs\ytm\resources\func.php on line 178
Fatal error: Call to a member function attributes() on a non-object in C:\xampp\htdocs\ytm\resources\func.php on line 181

Categories