Home>
I am studying PHP on the web. The last line is not displayed. What is wrong?
Expected display: hi, i am Bob!
Actual display: Fatal error ....
What should I do?
I don't know how to do this.
I use winndows10, Notepad ++, Xammp.
Please.
Notice: Undefined variable: bob in C: \ xampp \ htdocs \ php_sample \ php_lessons \ index_16.php on line 29
Fatal error: Uncaught Error: Call to a member function sayHi () on null in C: \ xampp \ htdocs \ php_sample \ php_lessons \ index_16.php: 29
Stack trace:
# 0 {main}
thrown in C: \ xampp \ htdocs \ php_sample \ php_lessons \ index_16.php on line 29
<? php
// Complex data structure
// User class
class User {
// Property = variable of class
// Define $name variable in Property
public $name;
// Constructor = called when a class is instantiated
public function __construct ($name) {
$this->name = $name;
}
// method
public function sayHi () {
echo "hi!, i am $this->name!";
}
}
$tom = new User ("Tom");
$bob = new User ("Bob");
echo $tom->name;// Tom
echo ('<pre>');// Line feed
$bob->sayHi ();// hi, i am Bob!
?>
-
Answer # 1
-
Answer # 2
name = $name; } // method public function sayHi () { echo "hi!, i am {$this->name}!"; } } $tom = new User ("Tom"); $bob = new User ("Bob"); echo $tom->name;// Tom echo ('
');// Line feed $bob->sayHi ();// hi, i am Bob! ?>
A double-byte space ...
I took it.
Related articles
- php - how to select and display the information (store name/address etc) registered in advance on the wordpress post page
- php - i want to display checkbox items for custom fields
- i want to check the form input with php, display an error on the same page if it is not filled in, and move to another page only
- php - i want to display the contents of a custom wordpress post with javascript on an html page
- php - [wordpress] i want to display the "new mark" in the navigation when there is a new article
- [php] the expected date and time is not returned by strtotime
- php - cannot display the value of the many-to-many relationship destination table in view
- php - i want to display an error or redirect
- php - "display option" is not displayed in the post list on the wordpress administration screen
- [php/laravel] i want to display all of a large amount of dom
- php - display the term list and attach a class to those linked to the post
- php - i want to display a list of articles that belong to both the current term and the term shared in the cpt ui
- php - i want to loop a multidimensional array and display it on a table
- display images side by side in php
- php - [laravel] i want to display the information of the related table in my page
- php - i want to display the website of the url entered in input in the html form in real time using iframe
- php - tweet display of users who are following with users who are logged in by joining laravel tables
- php - the display size of paging is strange
- php - i want to expand and display a nested array in view
- regarding repeated display in php
Trends