Skip to Content
プログラミングPHP 第4版
book

プログラミングPHP 第4版

by Kevin Tatroe, Peter MacIntyre, 永井 勝則, 中野 圭
April 2023
Intermediate to advanced
456 pages
6h 11m
Japanese
O'Reilly Japan, Inc.
Content preview from プログラミングPHP 第4版

2章PHP言語の基本

 本章では、PHP言語の基本機能をひと通り説明していきます。たとえば、データ型や変数、演算子、フロー制御文などについて取り上げます。PHPはPerlやCといった言語の影響を強く受けているので、これらの言語になじみのある方には、PHPを身につけるのはたやすいことでしょう。これまでに他のプログラミング言語を学んだことがないという方も、焦る必要はありません。まずはPHPプログラムの基本となる部分から説明を始めます。

2.1 字句構造

 プログラミング言語の字句構造とは、その言語でプログラムを書くにあたっての基本的なルールのことです。これはプログラミング言語の最も下位レベルの文法規則であり、変数名の形式やコメントに使用できる文字、それぞれの文を区切る方法などが含まれます。

2.1.1 大文字/小文字の区別

 ユーザが定義したクラスや関数の名前、そしてechowhileclassといった組み込みのキーワードの名前では、大文字/小文字が区別されません。したがって、次の3行は同じ意味になります。

echo("hello, world");
ECHO("hello, world");
EcHo("hello, world");

 一方、変数名では大文字/小文字が区別されます。つまり、$name$NAME$NaMEは、それぞれ異なる変数を表すことになります。

2.1.2 命令文とセミコロン

 命令文は、何らかの処理を行うPHPコードをまとめたものです。変数の代入のようなシンプルなものから、脱出点が複数ある複雑なループまで、さまざまです。PHPの命令文の例を次に示します。ここでは関数の呼び出し、変数への代入、そしてif文を取り上げています。

echo "Hello, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

プロダクトマネジメント ―ビルドトラップを避け顧客に価値を届ける

プロダクトマネジメント ―ビルドトラップを避け顧客に価値を届ける

Melissa Perri, 吉羽 龍太郎

Publisher Resources

ISBN: 9784814400270Other