PHP - New to OOP, already stuck -
I am starting with OOP because I have already written the procedural code adequately, which I have to move forward Want to
I started by creating a file 'user.class.php', writing some code, and loaded into the server.
& lt ;? Php class user {Private $ name; Private $ age; Function __ composition ($ name, age $) {$ this- & gt; Name = $ name; $ This- & gt; Age = age = age; } GetName function () {return $ this-> Name; } GetAge function () {return $ this-> Age; }} $ Usr = New User ('Alex', 16); Print ($ usr- & gt; getName. '& Lt; br & gt;'); Print ($ usr- & gt; getAge. '& Br>;');
I ran the code on the web server and found the following error:
Notice: Undefined property: Users: $ Milan / Library / Get in the webserver
The getAge function happens with the call.
If I can work this code then I would prefer better than initially, thanks in advance for writing more oo codes instead of just the procedural code.
You are just missing your parentheses for your method calls. Without them, you are trying to get a property named getName
that does not exist:
print ($ usr-> getName ()). & Lt; Br> '); Print ($ usr- & gt; getAge () '& lt; br & gt;');
Comments
Post a Comment