Hello everyone I have this class in php
<?php
namespace ExternalImporter\application\libs\pextractor\parser;
defined('\ABSPATH') || exit;
class Product {
public $link;
public $domain;
public $title;
public $description;
public $price;
public $currencyCode;
public $image;
public $oldPrice;
public $manufacturer;
public $inStock;
public $availability;
public $category;
public $condition;
public $ratingValue;
public $reviewCount;
public $features = array();
public $images = array();
public $reviews = array();
public $paused;
public $categoryPath = array();
public $extra = array();
}
However when this is called with a null value it gives me a fatal error.
I need that when this error occurs it returns the result: error25
I call the class like this in a function
public static function update(Product $newProduct, $product_id)
{
//code
}
In this example, $newProduct
has the value of NULL, which is why it would generate an error in the function.
If I can return the error string error25
I could handle it.
Note: If the solution is to call the function, it is much better than editing the class itself.
My goal is to achieve something like this, but I'm not sure you can in PHP
public static function update(Product $newProduct ?: "error25", $product_id)
{
//code
}
Edit Possible solution
public static function update($newProduct, $product_id)
{
if (empty($newProduct)) {
# CALL Product $newProduct how to do it?
}
else {
$newProduct = NULL;
}
}