katapofatico Posted March 17, 2016 Posted March 17, 2016 Excuse me if I don't understand but... ..on Responsive OSC index.php:62 we can see this line: if (isset($cPath) && strpos('_', $cPath)) { It seems that strpos() parameters are in reverse order, strpos() documentation says: mixed strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) I have a very-very old version of OSC and the same problem exists. Anybody can explain it to me, please?
burt Posted March 17, 2016 Posted March 17, 2016 http://www.oscommerce.com/forums/tracker/issue-699-indexphp-strpos-function/
MrPhil Posted March 17, 2016 Posted March 17, 2016 I seem to recall reading somewhere that old versions of PHP were pretty lenient about which was the "haystack" and which was the "needle", and could figure out which was which, but newer versions are strict about it. This could account for why the code is backwards. It worked eons ago, and no one noticed the switcheroo. Also note that strpos() returns false if the needle is not found in the haystack, but 0 if it is found at the beginning of the haystack! This trips up many coders, who fail to check for equivalence to false using === or !==. strpos() should never return true (=== true will never happen). In the case of $cPath, we should never see '_' (the needle) in position 0, so strpos($cPath, '_') should be safe (returns false if not found, or a position > 0 [== true] if found). Some coders like to prepend a junk character to the front of the string (e.g., 'x'.$haystack), but then have to subtract 1 from the returned position if they're doing more than just checking for the existence of the needle. strpos() would return 0/false if the needle is not found, and a position > 0 otherwise.
clustersolutions Posted March 18, 2016 Posted March 18, 2016 I thought it was corrected in BS... Another reference... http://www.oscommerce.com/forums/topic/399520-yet-another-question-about-cpath/
Recommended Posts
Archived
This topic is now archived and is closed to further replies.