Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Mutator method
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===PHP=== PHP defines the "magic methods" <code>__get</code>and<code>__set</code> for properties of objects.<ref>{{Cite web|title=PHP: Overloading - Manual|url=https://www.php.net/manual/en/language.oop5.overloading.php|access-date=2021-07-06|website=www.php.net}}</ref> In this example of a simple [[Class (computer science)|class]] representing a student with only the name stored, one can see the [[Variable (programming)|variable]] ''name'' is private, i.e. only visible from the Student class, and the "setter" and "getter" is public, namely the <code>getName()</code> and <code>setName('name')</code> methods. <syntaxhighlight lang="php"> class Student { private string $name; /** * @return string The name. */ public function getName(): string { return $this->name; } /** * @param string $newName The name to set. */ public function setName(string $newName): void { $this->name = $newName; } }</syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)