Author |
Message |
neralex
Site Admin
Joined: Aug 22, 2007
Posts: 1772
|
Posted:
Fri Apr 19, 2013 12:19 pm |
|
I have question for better understanding.
In some modules of RN25x i have seen the type-casting from a string to a integer inside the switch($op) cases and in other modules it was typed in the function self.
Code:switch ($op) {
default:
theindex(intval($new_topic));
break;
}
|
or inside a function:
Where is here the difference or what is the correct using? |
_________________ Github: RavenNuke |
|
|
|
spasticdonkey
RavenNuke(tm) Development Team
Joined: Dec 02, 2006
Posts: 1693
Location: Texas, USA
|
Posted:
Sat Apr 20, 2013 9:48 pm |
|
From my understanding, in terms of validating a $var that is an integer, they both do about the same thing. They can differ somewhat in how they handle values that are not integers. I usually use intval but not for any particular reason. someone else may have a better explanation... |
|
|
|
|
wHiTeHaT
Life Cycles Becoming CPU Cycles
Joined: Jul 18, 2004
Posts: 579
|
Posted:
Sun Apr 21, 2013 2:33 pm |
|
[ Only registered users can see links on this board! Get registered or login! ]
And:
[ Only registered users can see links on this board! Get registered or login! ] |
|
|
|
|
neralex
|
Posted:
Sun Apr 21, 2013 3:06 pm |
|
|
|
|
fkelly
Former Moderator in Good Standing
Joined: Aug 30, 2005
Posts: 3312
Location: near Albany NY
|
Posted:
Mon Apr 29, 2013 10:57 am |
|
In the context of Ravennuke, the excessive use of int and/or intval has always driven me a little ways up the wall. There are many cases such as $x=int($topic) where we are processing a variable that should be derived from the values in an integer field in the database. If a value in $topic is being passed in that is not an integer then some sort of error message should be generated. If the value of $topic is a string we are basically converting it to 0 (zero) with current logic and then going merrily along our way. It shouldn't work that way. You can't get a non-integer value out of an integer field and you shouldn't process it as the value 0.
Unfortunately we don't have any graceful error processing that would also provide manageable information to the site admin in RN. |
|
|
|
|
neralex
|
Posted:
Mon Apr 29, 2013 11:36 am |
|
Ok thanks. It seemed to me also a bit strange. From the logical point i'm totally with you. I saw this casting was used befor the value passed in a sql-query to ensure that the value is numeric. I personally use in this case a check with is_numeric($value) before i start the query. |
|
|
|
|
montego
Site Admin
Joined: Aug 29, 2004
Posts: 9457
Location: Arizona
|
Posted:
Thu May 02, 2013 4:49 pm |
|
Be careful as is_numeric() doesn't mean integer. It just means it is a number. When it comes to cleansing integer fields from outside (external) influences, either are fine but one does have to be careful, as fkelly has said, about changing the functional meaning. If having a string convert into '0' doesn't cause a functional issue, then what is the harm...
Complete agree that re-casting an integer field pulled straight from a DB call is just wasteful (was going to say "insane"). I think the same about saving encoded data to the database...
There is still a ton of legacy code even in RN2.51 today. We chip away at it as we open up modules and do major surgery. Call it "Progressive Correction" if you like. |
_________________ Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... |
|
|
|
|