PHP 연산자 우선순위

서열의 나라 헬조선 신민답게 누구 족보가 짱인지 제대로 알아두자

superhakgoman
Aug 28, 2017 · 2 min read

PHP7의 Null Coalescing Operator에 대해 쓴 글에서 이어진다

위 글 말미에 형변환 썼다가 에러난 이야기를 덧붙여놓고 우선순위를 언급했었는데 좀 더 자세히 정리해놔야겠다고 생각만 하고 초안만 던져놨다가 지금 발굴해서 다시 씀.

PHP 연산자 우선순위 문서 찾아보고 놀랐던 건 형변환이 상당히 우선도가 높은 연산이었다는 것… 아래 표를 참고하면 형변환은 인스턴스 생성/복제, 배열, **(산술 연산 중에서도 특히 이게 우선순위가 높고 ) 에 이어 증감연산자와 같은 순위에 놓여 있다.

http://php.net/manual/en/language.operators.precedence.php

Null Coalescing Operator(우리말로 뭐라고 하는지 알고 싶다)는 밑에서 세는 게 빠른 정도의 순위… 이러니 대충 (int)$foo->bar??’123'; 같은 식으로 막 쓰면 당연히 문제가 생기는 것… 이것은 버그가 아니라 사양입니다인 것…

더 쓰기 귀찮으니 메신저에서 왱알앵알했던거나 올려놔야지

문제인식
그걸 이제야 안 사람
확인된 사실로부터 확인되지 않은 사실로 넘어가는 중
결론 : 문송합니다

)
superhakgoman

Written by

I don speaks any emglish

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade