Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
1
10php
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yu Kimiduka
10php
Commits
fcca232c
Commit
fcca232c
authored
Jul 19, 2016
by
君塚 悠
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
プログラム作成(Triangle.class.php,cal.php:オブジェクト指向の学習)
parent
d6cb5a4d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
0 deletions
+64
-0
Triangle.class.php
php/php10/day10-1/Triangle.class.php
+41
-0
call.php
php/php10/day10-1/call.php
+23
-0
No files found.
php/php10/day10-1/Triangle.class.php
0 → 100644
View file @
fcca232c
<?php
class
Triangle
{
private
$width
;
private
$height
;
//コンストラクタ…クラスがインスタンス化されるときに呼び出される
public
function
__construct
()
{
$this
->
width
=
1
;
$this
->
heigh
=
1
;
}
//デストラクタ…破棄されるときに呼び出される
public
function
__destruct
(){
/*デストラクタ*/
}
public
function
get_width
()
{
return
$this
->
width
;}
public
function
get_height
(){
return
$this
->
height
;}
public
function
set_width
(
$width
)
{
if
(
i_numeric
(
$width
))
{
$this
->
width
=
$width
;
}
}
public
function
set_height
(
$height
)
{
if
(
is_numeric
(
$height
))
{
$this
->
height
=
$height
;
}
}
public
function
get_area
()
{
return
$this
->
get_width
()
*
$this
->
get_height
()
/
2
;
}
// static…静的メソッド。インスタンス化が必要ない。
// 固有の値をつかわない場合は、インスタンスの意味が無いため、静的にする。
public
static
function
calculate_area
(
$width
,
$height
)
{
return
$width
*
$height
/
2
;
}
}
?>
\ No newline at end of file
php/php10/day10-1/call.php
0 → 100644
View file @
fcca232c
<html>
<head>
<title>
オブジェクト指向入門
</title>
</head>
<body>
<h1
style =
"background:#cccccc"
>
オブジェクト入門
</h1>
<?php
// autoload関数の定義
function
__autoload
(
$name
)
{
require_once
(
$name
.
".class.php"
);
}
// Triangleクラスのインスタンス化
$objCls
=
new
Triangle
();
$objCls
->
set_width
(
10
);
$objCls
->
set_height
(
20
);
print
(
"三角形の面積:"
.
$objCls
->
get_area
()
.
"<br>"
);
print
(
"三角形の面積:"
.
Triangle
::
calculate_area
(
5
,
15
));
?>
</body>
</html>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment