bramwolf Posted May 4, 2020 Share Posted May 4, 2020 Hi Guys, I found that my site is producing this notice on the front end, even when $config->debug = false and also when admin is not even logged in. How do I keep the site from displaying this message to front end users? The notice is about a few vars being tested, which in this case aren't defined, how would I stop that from happing all together when testing vars? if I for instance wrap the $discountCode = blabla in a if($order) { ... } statement than I'm again testing for $order which isn't a object in this case which throws another notice.. This is the notice: Here is my current code: // PAD DISCOUNT CODE HOOK // First we see if we have active discount code if ($this->session->orderId) { $order = $this->pages->get($this->session->orderId); } if($product->geen_korting == 1) { $nodisc = $product->geen_korting; } else { $nodisc = $product->parent->geen_korting; } $discountCode = $this->sanitizer->selectorValue($order->pad_discount_code); $dc = $this->pages->get("template=paddiscount, title=$discountCode"); if ($dc->id) { if ($nodisc) { $discount = 0; } elseif ($dc->pad_percentage) { $discount = $newprice * ($dc->pad_percentage / 100); } } $event->return = $newprice - $discount; Thanks in advance ? Link to comment Share on other sites More sharing options...
MoritzLost Posted May 4, 2020 Share Posted May 4, 2020 Quote The notice is about a few vars being tested, which in this case aren't defined, how would I stop that from happing all together when testing vars? if I for instance wrap the $discountCode = blabla in a if($order) { ... } statement than I'm again testing for $order which isn't a object in this case which throws another notice.. You can check if a variable is defined with isset. This will not throw an error even if the variable does not exist in the current scope. If you want to also check if the variable is not empty (falsy), you can use empty, which will also not throw an error if the the variable does not exist. // this will throw a warning if $order does not exist if ($order) {} // this will never throw a warning, and will be true if $order is defined, even if it's value is null if (isset($order)) {} // this will never throw a warning, and will be true if $order is defined AND a holds non-falsy value if (!empty($order)) {} As a side note, in your production environment you should configure PHP to not display any errors on the webpage, and instead log those to a logfile that only you have access to. To do this, change the following settings in your PHP.ini: display_errors = Off display_startup_errors = Off error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT log_errors = On error_log = /path/to/error.log 4 Link to comment Share on other sites More sharing options...
bramwolf Posted May 4, 2020 Author Share Posted May 4, 2020 Thanks Moritzlost! That does just what I needed ? (Y) You rock! ? 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now