The knowledge points that the PHP teacher didn't teach you.

Source: Internet
Author: User

The knowledge points that the PHP teacher didn't teach you.

The alternative is a surprise.

When we read some of the source code, we find that there is an alternative way of writing, such as

Exception notation if (false = = $result)//Normal if ($result = = False)

In fact, this is a very clever way of writing, it can be to a large extent to eliminate the serious error caused by hand.

If we mistakenly write = = in the normal method, then if ($result = False) will always return true, resulting in an unknown bug in the actual operation, if the use of the exception of the wording of the hand becomes the wrong if (false = $false), The editor throws an error and we can find and fix the problem in time.

" try to omit

If a file has a blank line after?>, then you will return a warning headers already sent by XXX when using session_start (), because session_start () requires no output before use.

Similarly

When strings and numbers are together, be careful

Var_dump (' a '. 0); Return error, syntax error

The solution is relatively simple, as long as the. Connection and left and right add a space to prevent grammatical errors.

Var_dump (' abc ' = = 0); Output truevar_dump (' 1abc ' = = 0); Output false

The output of true in this example is not surprising to you, in fact, PHP will compare strings and numbers, the string is cast to int, the conversion rule is if the string is the beginning of a number, then take the first number as the result of the conversion, if the beginning is not a number then 0

The arithmetic of string, you can't provoke

for ($i = ' a '; $i <= ' z '; + + $i) {    echo "$i";}

Do you think it will output from A to Z? Then you're wrong, you're blind. The output is as follows:

A b c d e F g h i j k l m n o p q R S t u v w x y z aa ab AC ad AE af ag ah AI aj Ak al am an AO ap aq ar as at au av aw A x ay az ba bb BC BD is BF BG BH BI BJ BK bl bm bn bo BP bq br bs BT BU BV bw BX by BZ CA CB CC CD CE CF CG ch CI CJ CK cl  CM CN CO CP CQ CR CS CT CU CV cw cx cy CZ da DB DC dd de DF dg DH di dj DK dl DM DN Do DP dq Dr ds dt du dv DW dx dy DZ ea EB ec ed ee ef eg eh el ej ek el em en eo ep eq er es et eu ev ew EX EY EZ FA FB FC FD FE FF FG fh FI FJ FK FL FM fn FO f P FQ fr fs ft fu FV FW fx FY FZ GA GB GC GD GE GF GG GH gi GJ GK GL GM gn go GP GQ gr GS gt gu gv GW gx gy GZ ha HB HC HD  He hf Hg HH Hi HJ HK HL HM hn HO HP HQ HR HS HT hu HV HW HX hy Hz IA IB IC ID ie if IG ih ii ij ik il im in io IP iq ir is It IU IV iw IX iy iz ja jb JC JD JE jf jg JH ji JJ JK JL JM Jn Jo JP JQ Jr JS JT Ju JV jw jx jy jz ka kb kc kd ke kf kg k H ki kj kk kl miles kn ko kp kq kr ks kt ku KV KW kx ky KZ la lb LC ld le LF lg LH Li LJ lk ll LM LN LO LP LQ LR LS lt lu lv LW LX ly LZ MA MB MC MDMe mf mg MH mi MJ mk ml mm MN Mo MP MQ Mr Ms Mt MU mv MW mx my mz na nb nc nd ne nf ng nh ni nj nk nl nm NN no NP NQ nr NS NT Nu NV NW NX NY NZ OA ob oc od oe of og oh oi oj ok ol om on oo op oq or os ot ou ov ow ox oy oz PA pb pc PD PE PF PG P H Pi PJ Pk pl pm PN PO pp PQ PR PS pt PU PV pw px py pz QA QB QC QD QE QF QG QH qi qj qk ql QM qn qo qp qq qr Qs qt qu QV  QW qx qy QZ ra RB RC Rd RE RF RG RH RI RJ RK RL RM RN RO RP RQ rr rs rt ru RV rw rx ry rz sa sb sc sd se SF sg sh si sj SK SL SM SN So sp sq SRS SS St Su SV SW sx sy SZ TA TB tc TD te TF tg th ti TJ tk tl TM TN to TP TQ TR ts TT tu TV tw tx ty t Z UA UB UC UD UE uf UG UH UI UJ UK ul um un uo up UQ ur us ut uu uv uw ux uy uz va vb vc VD ve VF VG VH VI VJ VK VL VM VN  VO VP VQ VR vs VT vu VV VW VX VY VZ wa WB WC WD WE WF WG WH WI WJ wk wl wm wn wo wp wq WR ws WT Wu WV WW WX WY wz XA XB XC XD XE XF xg XH XI xj xk XL xm xn xo xp XQ XR XS xt Xu XV xw xx xy XZ ya yb yc yd ye yf yg yh yi yj yk yl ym yn yo yp yq y R ys yt yu yv yw yx yy yZ  

Always be careful of the loss of precision

$f = 0.58;echo intval ($f * 100); Output 57sprintf ("%.2f", $f * 100); Output 58.00

The problem of loss of precision is there in other languages, but more attention is needed in the weakly typed language of PHP.

In fact, the above mentioned problems in the PHP manual has been referred to, manual turn times code, such as God, a certain amount of careful experience, you will be able to develop the road pits all the way forward.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.