php - What's the best way to get rid of notices about undefined variables? -


i use codeigniter, 1 of main issues have views undefined variables may or may not exist.

i know it's easy rid of notices when using like:

<?=html($this->input->post('name'))?> 

by adding if(isset(..){ html($this->input->post('name')); }

but it's annoying , makes code ugly, don't want disable notice reporting.

is there advice that?

the "best" way? still it's isset. it's nice explicit, , me, maintaining code later, realize okay variable not existing , wasn't mistake. unless isset check there, i'd assume didn't realize possible not set, , wonder meant do.

additionally, i'd assert 1 of main reasons looks ugly because code being crammed 1 line. there 2 things you're trying do: check if it's set, , print if so. maybe spacing them out nicer, if it's bit more verbose:

<?php if( isset($this->input->post('name')) ): ?>     <?= $this->input->post('name') ?> <?php endif ?> 

this makes snippet easier manage later, in case later decide to, say, wrap output in html tag, or add else case.

plus, since, according question, can't mess error reporting settings, checking variable's existence only option. sorry. either check if it's set, or disable error messages saying it's not. no middle road.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -