0

Here's my code

$q->addNotInCondition('`t`.`id`', array(0, 1, 2));

I want to remove magic numbers in array. Is there a special way to do this or just define 0 , 1 and 2 ?

Is this correct?

const ONE= 4;
const TWO= 2;
const THREE= 4;

$q->addNotInCondition('`t`.`id`', array(ONE, TWO, THREE));
Sampath Wijesinghe
  • 789
  • 1
  • 11
  • 33
  • 2
    what is the meaning of magic numbers? also, please describe your problem more – sachin kumara liyanage Jun 04 '20 at 07:31
  • @sachinkumaraliyanage machan, A magic number is a direct usage of a number in the code. have to getting rid of it and want to know there is specific way to do. – Sampath Wijesinghe Jun 04 '20 at 07:38
  • why do you care about doing this, in this specific case? What are you trying to achieve? Do you want these values to come from user input instead? Or you just want to label them and give them meaning? – ADyson Jun 04 '20 at 09:01
  • @ADyson yes, It's some thing like labeling. – Sampath Wijesinghe Jun 04 '20 at 09:17
  • 2
    well ok you could use constants yes, or maybe fetch them from an associative array. There are probably a few ways to do it, in fact. None is "right" or "wrong" really, as long as it helps you to improve your code in a way you find useful. – ADyson Jun 04 '20 at 09:20

0 Answers0