{"id":842,"date":"2025-08-05T16:29:07","date_gmt":"2025-08-05T07:29:07","guid":{"rendered":"https:\/\/nexive.tech\/?p=842"},"modified":"2025-08-05T16:29:09","modified_gmt":"2025-08-05T07:29:09","slug":"%e3%80%90%e3%82%b5%e3%82%af%e3%83%83%e3%81%a8%e8%a7%a3%e8%aa%ac%e3%80%91php-oop%e3%81%b8%e3%83%aa%e3%83%95%e3%82%a1%e3%82%af%e3%82%bf%e3%83%aa%e3%83%b3%e3%82%b0%e3%81%99%e3%82%8b%e5%9f%ba%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/nexive.tech\/?p=842","title":{"rendered":"\u3010\u30b5\u30af\u30c3\u3068\u89e3\u8aac\u3011PHP OOP\u3078\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u3059\u308b\u57fa\u672c\u624b\u9806"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1. \u672c\u8a18\u4e8b\u306e\u30dd\u30a4\u30f3\u30c8<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>PHP\u306e\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u30eb\u30b3\u30fc\u30c9\u3092OOP\uff08\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\uff09\u3078\u5909\u63db\u3059\u308b\u57fa\u672c\u624b\u9806\u3092\u89e3\u8aac<\/li>\n\n\n\n<li>\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u6642\u306e\u5178\u578b\u30d1\u30bf\u30fc\u30f3\u3068\u5b9f\u52d9\u5224\u65ad\u306e\u30dd\u30a4\u30f3\u30c8\u3092\u7d39\u4ecb<\/li>\n\n\n\n<li>\u30b3\u30fc\u30c9\u306e\u4fdd\u5b88\u6027\u3084\u62e1\u5f35\u6027\u3092\u610f\u8b58\u3057\u305f\u8a2d\u8a08\u3078\u306e\u8db3\u304c\u304b\u308a\u306b<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">2. PHP\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u30eb\u304b\u3089OOP\u3078\u306e\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u3068\u306f\uff1f<\/h2>\n\n\n\n<p>PHP\u306f\u3082\u3068\u3082\u3068\u30b9\u30af\u30ea\u30d7\u30c8\u8a00\u8a9e\u3068\u3057\u3066\u3001HTML\u57cb\u3081\u8fbc\u307f\u578b\u306e\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u30eb\u30b3\u30fc\u30c9\uff08\u624b\u7d9a\u304d\u578b\uff09\u3092\u4e2d\u5fc3\u306b\u767a\u5c55\u3057\u3066\u304d\u307e\u3057\u305f\u3002\u3057\u304b\u3057\u3001\u8fd1\u5e74\u3067\u306f\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3092\u542b\u3080\u591a\u304f\u306e\u73fe\u5834\u3067\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\uff08OOP\uff09\u304c\u6a19\u6e96\u5316\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u30eb\u30b3\u30fc\u30c9\u3067\u306f\u3001\u51e6\u7406\u306e\u6d41\u308c\u3092\u4e0a\u304b\u3089\u9806\u306b\u66f8\u304d\u4e26\u3079\u3001\u95a2\u6570\u3084\u5909\u6570\u3092\u30b0\u30ed\u30fc\u30d0\u30eb\u306b\u6271\u3046\u3053\u3068\u304c\u591a\u304f\u3001\u30b9\u30af\u30ea\u30d7\u30c8\u304c\u5927\u304d\u304f\u306a\u308b\u306b\u3064\u308c\u4fdd\u5b88\u6027\u306b\u8ab2\u984c\u304c\u51fa\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002\u4e00\u65b9\u3001OOP\u3067\u306f\u30c7\u30fc\u30bf\u3068\u51e6\u7406\u3092\u30af\u30e9\u30b9\u3068\u3057\u3066\u6574\u7406\u3057\u3001\u518d\u5229\u7528\u6027\u3084\u62e1\u5f35\u6027\u3001\u30c6\u30b9\u30c8\u306e\u3057\u3084\u3059\u3055\u304c\u5411\u4e0a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u672c\u8a18\u4e8b\u3067\u306f\u3001\u5178\u578b\u7684\u306a\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u30eb\u30b3\u30fc\u30c9\u3092OOP\u306b\u66f8\u304d\u63db\u3048\u308b\u904e\u7a0b\u3092\u901a\u3058\u3066\u3001\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u306e\u5b9f\u52d9\u7684\u306a\u8003\u3048\u65b9\u3084\u6ce8\u610f\u70b9\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u8a73\u7d30\u89e3\u8aac<\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u7c21\u5358\u306a\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u30eb\u30b3\u30fc\u30c9\u304b\u3089\u30b9\u30bf\u30fc\u30c8\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u5546\u54c1\u4fa1\u683c\u306b\u7a0e\u7387\u3092\u52a0\u5473\u3057\u3066\u7a0e\u8fbc\u4fa1\u683c\u3092\u51fa\u529b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>\/\/ \u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u30eb\u306a\u51e6\u7406\nfunction calcTax($price) {\n    return $price * 1.1; \/\/ \u7a0e\u738710%\n}\n\n$price = 1000;\necho '\u7a0e\u8fbc\u4fa1\u683c: ' . calcTax($price);\n\/\/ \u51fa\u529b: \u7a0e\u8fbc\u4fa1\u683c: 1100\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u30eb\u306a\u51e6\u7406<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">calcTax<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$price<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$price<\/span><span style=\"color: #D4D4D4\"> * <\/span><span style=\"color: #B5CEA8\">1.1<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #6A9955\">\/\/ \u7a0e\u738710%<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$price<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">1000<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&#39;\u7a0e\u8fbc\u4fa1\u683c: &#39;<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">calcTax<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$price<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u51fa\u529b: \u7a0e\u8fbc\u4fa1\u683c: 1100<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u306e\u51e6\u7406\u3092OOP\u306b\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u3057\u3066\u307f\u307e\u3059\u3002\u307e\u305a\u306f\u51e6\u7406\u3092\u30af\u30e9\u30b9\u5316\u3057\u3001\u8cac\u52d9\u3092\u5206\u96e2\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>\/\/ \u5358\u4e00\u8cac\u4efb\u306b\u57fa\u3065\u304f\u8a2d\u8a08\nclass TaxCalculator {\n    private float $rate;\n\n    public function __construct(float $rate = 0.1) {\n        $this->rate = $rate;\n    }\n\n    public function withTax(float $price): float {\n        return $price * (1 + $this->rate);\n    }\n}\n\n$calculator = new TaxCalculator();\necho '\u7a0e\u8fbc\u4fa1\u683c: ' . $calculator->withTax(1000);\n\/\/ \u51fa\u529b: \u7a0e\u8fbc\u4fa1\u683c: 1100\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u5358\u4e00\u8cac\u4efb\u306b\u57fa\u3065\u304f\u8a2d\u8a08<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">class<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">TaxCalculator<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">private<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">float<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$rate<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">public<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">__construct<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">float<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$rate<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">0.1<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #569CD6\">$this<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #9CDCFE\">rate<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">$rate<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">public<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">withTax<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">float<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$price<\/span><span style=\"color: #D4D4D4\">): <\/span><span style=\"color: #569CD6\">float<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$price<\/span><span style=\"color: #D4D4D4\"> * (<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\"> + <\/span><span style=\"color: #569CD6\">$this<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #9CDCFE\">rate<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$calculator<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #569CD6\">new<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">TaxCalculator<\/span><span style=\"color: #D4D4D4\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&#39;\u7a0e\u8fbc\u4fa1\u683c: &#39;<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$calculator<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">withTax<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">1000<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u51fa\u529b: \u7a0e\u8fbc\u4fa1\u683c: 1100<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u6b21\u306b\u3001\u5916\u90e8\u5165\u529b\u3092\u542b\u3080\u51e6\u7406\u306b\u5bfe\u5fdc\u3059\u308b\u305f\u3081\u306e\u30af\u30e9\u30b9\u69cb\u6210\u3092\u691c\u8a0e\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306f\u300c\u5546\u54c1\u300d\u3068\u300c\u4fa1\u683c\u8a08\u7b97\u300d\u306e\u95a2\u5fc3\u3092\u5206\u96e2\u3057\u305f\u4f8b\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">PHP<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>class Product {\n    public function __construct(\n        private string $name,\n        private float $price\n    ) {}\n\n    public function getPrice(): float {\n        return $this->price;\n    }\n}\n\nclass TaxCalculator {\n    public function __construct(private float $rate = 0.1) {}\n\n    public function calculate(Product $product): float {\n        return $product->getPrice() * (1 + $this->rate);\n    }\n}\n\n$product = new Product('T\u30b7\u30e3\u30c4', 2500);\n$calculator = new TaxCalculator();\necho '\u7a0e\u8fbc\u4fa1\u683c: ' . $calculator->calculate($product);\n\/\/ \u51fa\u529b: \u7a0e\u8fbc\u4fa1\u683c: 2750\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">class<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">Product<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">public<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">__construct<\/span><span style=\"color: #D4D4D4\">(<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #569CD6\">private<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">string<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$name<\/span><span style=\"color: #D4D4D4\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #569CD6\">private<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">float<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$price<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    ) {}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">public<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">getPrice<\/span><span style=\"color: #D4D4D4\">(): <\/span><span style=\"color: #569CD6\">float<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">$this<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #9CDCFE\">price<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">class<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">TaxCalculator<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">public<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">__construct<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">private<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">float<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$rate<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">0.1<\/span><span style=\"color: #D4D4D4\">) {}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">public<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">function<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">calculate<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">Product<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$product<\/span><span style=\"color: #D4D4D4\">): <\/span><span style=\"color: #569CD6\">float<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #C586C0\">return<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$product<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">getPrice<\/span><span style=\"color: #D4D4D4\">() * (<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\"> + <\/span><span style=\"color: #569CD6\">$this<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #9CDCFE\">rate<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$product<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #569CD6\">new<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">Product<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&#39;T\u30b7\u30e3\u30c4&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">2500<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$calculator<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #569CD6\">new<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">TaxCalculator<\/span><span style=\"color: #D4D4D4\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">echo<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&#39;\u7a0e\u8fbc\u4fa1\u683c: &#39;<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$calculator<\/span><span style=\"color: #D4D4D4\">-&gt;<\/span><span style=\"color: #DCDCAA\">calculate<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">$product<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u51fa\u529b: \u7a0e\u8fbc\u4fa1\u683c: 2750<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306b\u3001OOP\u3067\u306f\u72b6\u614b\u3068\u632f\u308b\u821e\u3044\u3092\u9069\u5207\u306b\u30af\u30e9\u30b9\u3078\u5206\u3051\u308b\u3053\u3068\u3067\u3001\u5909\u66f4\u3084\u62e1\u5f35\u3078\u306e\u8010\u6027\u304c\u5411\u4e0a\u3057\u307e\u3059\u3002\u307e\u305f\u3001DI\uff08\u4f9d\u5b58\u6027\u6ce8\u5165\uff09\u3084\u30c6\u30b9\u30c8\u30d5\u30ec\u30f3\u30c9\u30ea\u30fc\u306a\u69cb\u6210\u306b\u3082\u3064\u306a\u304c\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u3088\u304f\u3042\u308b\u30df\u30b9\u30fb\u8aa4\u89e3\u30fb\u843d\u3068\u3057\u7a74<\/h2>\n\n\n\n<p>OOP\u5316\u306b\u304a\u3044\u3066\u300c\u306a\u3093\u3067\u3082\u30af\u30e9\u30b9\u5316\u3059\u308c\u3070\u3088\u3044\u300d\u3068\u8aa4\u89e3\u3057\u304c\u3061\u3067\u3059\u304c\u3001\u69cb\u9020\u3092\u5206\u3051\u308b\u610f\u56f3\u304c\u4e0d\u660e\u77ad\u306a\u5834\u5408\u3001\u304b\u3048\u3063\u3066\u53ef\u8aad\u6027\u304c\u4e0b\u304c\u308b\u5371\u967a\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u307e\u305f\u3001getter\/setter\u3060\u3051\u3092\u6301\u3064\u30c7\u30fc\u30bf\u30b3\u30f3\u30c6\u30ca\u306e\u4e71\u7528\u3084\u3001\u95a2\u5fc3\u306e\u6df7\u3056\u3063\u305fGod Object\u7684\u8a2d\u8a08\u3082\u3088\u304f\u898b\u3089\u308c\u307e\u3059\u3002\u8a2d\u8a08\u306e\u76ee\u7684\u306f\u300c\u6574\u7406\u300d\u3084\u300c\u518d\u5229\u7528\u6027\u306e\u5411\u4e0a\u300d\u3067\u3042\u308b\u3053\u3068\u3092\u5fd8\u308c\u305a\u3001\u51e6\u7406\u3084\u30c7\u30fc\u30bf\u306e\u307e\u3068\u307e\u308a\u3092\u610f\u8b58\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p>\u3055\u3089\u306b\u3001\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3092\u305d\u306e\u307e\u307e\u30af\u30e9\u30b9\u306b\u6301\u3061\u8fbc\u3093\u3067\u3057\u307e\u3044\u3001\u72b6\u614b\u7ba1\u7406\u304c\u7169\u96d1\u306b\u306a\u308b\u30b1\u30fc\u30b9\u3082\u591a\u304f\u3042\u308a\u307e\u3059\u3002OOP\u3067\u306f\u30b9\u30b3\u30fc\u30d7\u3084\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\u3092\u9069\u5207\u306b\u7ba1\u7406\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. \u307e\u3068\u3081<\/h2>\n\n\n\n<p>PHP\u306e\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u30eb\u30b3\u30fc\u30c9\u3092OOP\u3078\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u3059\u308b\u3053\u3068\u3067\u3001\u4fdd\u5b88\u6027\u3084\u62e1\u5f35\u6027\u304c\u5411\u4e0a\u3057\u307e\u3059\u3002\u5358\u7d14\u306a\u95a2\u6570\u547c\u3073\u51fa\u3057\u304b\u3089\u30b9\u30bf\u30fc\u30c8\u3057\u3001\u8cac\u52d9\u306b\u5fdc\u3058\u3066\u30af\u30e9\u30b9\u3092\u5206\u96e2\u30fb\u69cb\u6210\u3059\u308b\u3053\u3068\u304c\u57fa\u672c\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u305f\u3060\u3057\u3001\u904e\u5ea6\u306a\u62bd\u8c61\u5316\u3084\u30af\u30e9\u30b9\u5316\u306f\u9006\u52b9\u679c\u306b\u306a\u308b\u305f\u3081\u3001\u300c\u3069\u306e\u3088\u3046\u306a\u76ee\u7684\u3067\u5206\u3051\u308b\u304b\u300d\u3092\u660e\u78ba\u306b\u610f\u8b58\u3057\u306a\u304c\u3089\u9032\u3081\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u672c\u8a18\u4e8b\u306e\u30dd\u30a4\u30f3\u30c8 2. PHP\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u30eb\u304b\u3089OOP\u3078\u306e\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u3068\u306f\uff1f PHP\u306f\u3082\u3068\u3082\u3068\u30b9\u30af\u30ea\u30d7\u30c8\u8a00\u8a9e\u3068\u3057\u3066\u3001HTML\u57cb\u3081\u8fbc\u307f\u578b\u306e\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u30eb\u30b3\u30fc\u30c9\uff08\u624b\u7d9a\u304d\u578b\uff09\u3092\u4e2d\u5fc3\u306b\u767a\u5c55\u3057\u3066\u304d\u307e\u3057\u305f\u3002\u3057\u304b\u3057\u3001\u8fd1\u5e74\u3067\u306f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":920,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[85],"tags":[],"class_list":["post-842","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/842","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=842"}],"version-history":[{"count":2,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/842\/revisions"}],"predecessor-version":[{"id":921,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/842\/revisions\/921"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/media\/920"}],"wp:attachment":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}