marrtins Posted March 6, 2013 Report Share Posted March 6, 2013 Nu pati flaga uzstādīšana un noņemšana nevajadzētu tik dramatiski ietekmēt performanci. Nez kāda vella pēc viņi tur šādi ņemās... Quote Link to comment Share on other sites More sharing options...
Kavacky Posted March 6, 2013 Report Share Posted March 6, 2013 Gribu piebilst, ka issetus bezjēgā lietot arī nav risinājums. Ja mainīgajam jābūt definētam, tad issetu nevajadzētu lietot, lai pamanītu situācju, kad tas tā ir. Isset ir normāls mehānisms, lai pārbaudītu nezināma satura masīvus vai noteiktu, ka skatam ir uzsetots parametrs, piemēram. Quote Link to comment Share on other sites More sharing options...
aaxc Posted March 6, 2013 Author Report Share Posted March 6, 2013 Es parasti isset izmantoju uz sesijas mainiigajiem, respektiivi, paarbaudu, vai konkreets mainiigais ir vai nav uzsetots, jo predefineet visus negrasos. Pie tam, tas arii lieku atminju norij. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted March 6, 2013 Report Share Posted March 6, 2013 Nav PHP šāds veids? `"key" in my_array` Quote Link to comment Share on other sites More sharing options...
marrtins Posted March 6, 2013 Report Share Posted March 6, 2013 Kombinējot in_array un array_keys, bet nu labāk, protams, ir isset, ja zināms key. Quote Link to comment Share on other sites More sharing options...
F3llony Posted March 6, 2013 Report Share Posted March 6, 2013 Nav PHP šāds veids? `"key" in my_array` if(isset($array[$key][$subkey][$wtf][$areyouserious][$stop][$seriously])){ } Quote Link to comment Share on other sites More sharing options...
v3rb0 Posted March 7, 2013 Report Share Posted March 7, 2013 un atceramies, ka key ar var nebūt, tos ar jāpārbauda :> if (isset($key, $subkey, $wtf, $areyouserious, $stop, $seriously, $array, $array[$key], $array[$key][$subkey], $array[$key][$subkey][$wtf], $array[$key][$subkey][$wtf][$areyouserious], $array[$key][$subkey][$wtf][$areyouserious][$stop], $array[$key][$subkey][$wtf][$areyouserious][$stop][$seriously])) .. Quote Link to comment Share on other sites More sharing options...
aaxc Posted March 7, 2013 Author Report Share Posted March 7, 2013 Kas vainas šim? $test = 3; $array = array( 0=>1, 1=>2, 2=>3 ); if (array_key_exists( $test, $array ) ) echo 'true'; else echo 'false'; Quote Link to comment Share on other sites More sharing options...
daGrevis Posted March 7, 2013 Report Share Posted March 7, 2013 ~~~ try: x["y"]["z"] except KeyError: print "Kkas līdzīgs šim ir?" ~~~ Quote Link to comment Share on other sites More sharing options...
F3llony Posted March 7, 2013 Report Share Posted March 7, 2013 ~~~ try: x["y"]["z"] except KeyError: print "Kkas līdzīgs šim ir?" ~~~ Ekscepšani validācijai? :> Nu fuj, kas tad tā dara... :> Quote Link to comment Share on other sites More sharing options...
daGrevis Posted March 7, 2013 Report Share Posted March 7, 2013 Eksepšens, ka nav kījs iekš arraja. Quote Link to comment Share on other sites More sharing options...
F3llony Posted March 7, 2013 Report Share Posted March 7, 2013 Eksepšens, ka nav kījs iekš arraja. Tā gluži nebūs gan. Izņēmumi tiek izmantoti lai izķertu anomālus, nekontrolējamus notikumus programmas izpildē pārslēdzot izpildes stāvokli programmā. Neesošs key nav ne anomālija, ne nekontrolējams notikums. Tā ir datu validacijas problēma. Itkā konceptuāla kļūda, bet drausmīgi kaitinoša. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted March 7, 2013 Report Share Posted March 7, 2013 A kur ir problēma izmantot eksepšenus arī validācijai? Quote Link to comment Share on other sites More sharing options...
F3llony Posted March 7, 2013 Report Share Posted March 7, 2013 Tu odus vasarā arī sit ar Trident SLBM? Quote Link to comment Share on other sites More sharing options...
Kavacky Posted March 7, 2013 Report Share Posted March 7, 2013 (edited) Exceptions tur ļoti normāli iederas. try { do shit with this key } catch { nah key not found } PS: Valoda vispār ir instrumentu kopums, nevis instrukcijas par to lietošanu. Ja ar instrumentiem var izveidot loģisku un efektīvāku sistēmu, tad tos tā var lietot. Edited March 7, 2013 by Kavacky Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.