public function php

Solutions on MaxInterview for public function php by the best coders in the world

showing results for - "public function php"
Luna
26 Jan 2017
1<?php
2class Fruit {
3  public $name;
4  public $color;
5  public $weight;
6
7  function set_name($n) {  // a public function (default)
8    $this->name = $n;
9  }
10  protected function set_color($n) { // a protected function
11    $this->color = $n;
12  }
13  private function set_weight($n) { // a private function
14    $this->weight = $n;
15  }
16}
17
18$mango = new Fruit();
19$mango->set_name('Mango'); // OK
20$mango->set_color('Yellow'); // ERROR
21$mango->set_weight('300'); // ERROR
22?>
23  
Kimberly
29 Apr 2019
1<?php
2class Fruit {
3  public $name;
4  public $color;
5  public $weight;
6
7  function set_name($n) {  // a public function (default)
8    $this->name = $n;
9  }
10  protected function set_color($n) { // a protected function
11    $this->color = $n;
12  }
13  private function set_weight($n) { // a private function
14    $this->weight = $n;
15  }
16}
17
18$mango = new Fruit();
19$mango->set_name('Mango'); // OK
20$mango->set_color('Yellow'); // ERROR
21$mango->set_weight('300'); // ERROR
22?>