429,515 Members | 1,363 Online
Need help? Post your question and get tips & solutions from a community of 429,515 IT Pros & Developers. It's quick & easy.

# still not working: why?

 P: n/a hi guys, i'm just at the beginning. I apologize. the file still gives me back an error: <> why? Can someone fix it so i can "study" the working one? class somma { var \$uno=10; var \$due=15; var \$tre=15; function sum(\$uno, \$due, \$tre) { \$totale = \$uno + \$due + \$tre; return(\$totale); } function sum_2() { \$totale = \$this->sum(\$this->uno, \$this- >due, \$this->tre); return \$totale; print("\$totale"); } \$somma=new_somma(); \$sum=\$somma->(34,40); print("\$sum"); } May 29 '07 #1
6 Replies

 P: n/a vinnie wrote: hi guys, i'm just at the beginning. I apologize. the file still gives me back an error: <> why? Can someone fix it so i can "study" the working one? class somma { var \$uno=10; var \$due=15; var \$tre=15; function sum(\$uno, \$due, \$tre) { \$totale = \$uno + \$due + \$tre; return(\$totale); } function sum_2() { \$totale = \$this->sum(\$this->uno, \$this- >due, \$this->tre); return \$totale; print("\$totale"); } \$somma=new_somma(); \$sum=\$somma->(34,40); print("\$sum"); } You didn't tell what function to call. When you create an object, you create something with both properties and methods. You interact with the properties through the methods. In this case you're not really using any of the properties of the class (\$uno, \$due, \$tre). Rather, you're just trying to call a function with some parameters. OOP is a very different way of thinking, but (IMHO) a much superior way of programming. For instance, in your class, you might want functions to set \$somma->uno, \$somma->dup and \$somma->tre, then have a function which would add the three. While not particularly useful in this instance, it would be a more accurate example of OOP. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. js*******@attglobal.net ================== May 29 '07 #2

 P: n/a On May 28, 10:05 pm, Jerry Stuckle > why? Can someone fix it so i can "study" the working one? class somma { var \$uno=10; var \$due=15; var \$tre=15; function sum(\$uno, \$due, \$tre) { \$totale = \$uno + \$due + \$tre; return(\$totale); } function sum_2() { \$totale = \$this->sum(\$this->uno, \$this- due, \$this->tre); return \$totale; print("\$totale"); } \$somma=new_somma(); \$sum=\$somma->(34,40); print("\$sum"); } You didn't tell what function to call. When you create an object, you create something with both properties and methods. You interact with the properties through the methods. In this case you're not really using any of the properties of the class (\$uno, \$due, \$tre). Rather, you're just trying to call a function with some parameters. OOP is a very different way of thinking, but (IMHO) a much superior way of programming. For instance, in your class, you might want functions to set \$somma->uno, \$somma->dup and \$somma->tre, then have a function which would add the three. While not particularly useful in this instance, it would be a more accurate example of OOP. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstuck...@attglobal.net ================== so, writing back the whole algorithm, how should it be? thanks May 29 '07 #3

 P: n/a At Mon, 28 May 2007 16:56:34 -0700, vinnie let h(is|er) monkeys type: hi guys, i'm just at the beginning. I apologize. the file still gives me back an error: <> why? Can someone fix it so i can "study" the working one? class somma { var \$uno=10; var \$due=15; var \$tre=15; function sum(\$uno, \$due, \$tre) { \$totale = \$uno + \$due + \$tre; return(\$totale); } function sum_2() { \$totale = \$this->sum(\$this->uno, \$this- >>due, \$this->tre); return \$totale; print("\$totale"); } \$somma=new_somma(); \$sum=\$somma->(34,40); print("\$sum"); } Vinnie, are you sure this isn't homework (again!) ? Your first msg clearly stated: please help me, i have a test! I cannot help but think you hardly have a clue about PHP's syntax and semantics. If you read the replies carefully the answer is already there, but it seems you just want us to deliver the working code for you. Sorry, no can do. -- Schraalhans Keukenmeester - sc*********@the.spamtrapexample.nl [Remove the lowercase part of Spamtrap to send me a message] "strcmp('apples','oranges') is -1" May 29 '07 #4

 P: n/a vinnie wrote: hi guys, i'm just at the beginning. I apologize. the file still gives me back an error: <> why? Can someone fix it so i can "study" the working one? class somma { var \$uno=10; var \$due=15; var \$tre=15; function sum(\$uno, \$due, \$tre) { \$totale = \$uno + \$due + \$tre; return(\$totale); } function sum_2() { \$totale = \$this->sum(\$this->uno, \$this- >>due, \$this->tre); return \$totale; print("\$totale"); Hi Vinnie, Why do you first return something, and then print something on the next line? What do you think will happen? Will the print-statement ever be reached? Regards, Erwin Moller } \$somma=new_somma(); \$sum=\$somma->(34,40); print("\$sum"); } May 29 '07 #5

 P: n/a On May 29, 3:54 am, Erwin Moller > why? Can someone fix it so i can "study" the working one? class somma { var \$uno=10; var \$due=15; var \$tre=15; function sum(\$uno, \$due, \$tre) { \$totale = \$uno + \$due + \$tre; return(\$totale); } function sum_2() { \$totale = \$this->sum(\$this->uno, \$this- >due, \$this->tre); return \$totale; print("\$totale"); Hi Vinnie, Why do you first return something, and then print something on the next line? What do you think will happen? Will the print-statement ever be reached? Regards, Erwin Moller } \$somma=new_somma(); \$sum=\$somma->(34,40); print("\$sum"); } but also if i try to echo \$sum, i get nothing, so there must be a mistake somewhere, and using the 2 books i have it's hard to find (PHP5 for dummies, and core PHP programming). May 29 '07 #6

 P: n/a vinnie wrote: On May 29, 3:54 am, Erwin Moller vinnie wrote: >>hi guys, i'm just at the beginning. I apologize. the file still givesme back an error:<>why? Can someone fix it so i can "study" the working one?class somma { var \$uno=10; var \$due=15; var \$tre=15; function sum(\$uno,\$due, \$tre) {\$totale = \$uno + \$due + \$tre;return(\$totale); } function sum_2() { \$totale = \$this->sum(\$this->uno, \$this-due, \$this->tre); return \$totale; print("\$totale"); Hi Vinnie,Why do you first return something, and then print something on the nextline?What do you think will happen?Will the print-statement ever be reached?Regards,Erwin Moller >> }\$somma=new_somma();\$sum=\$somma->(34,40);print("\$sum"); } but also if i try to echo \$sum, i get nothing, so there must be a mistake somewhere, and using the 2 books i have it's hard to find (PHP5 for dummies, and core PHP programming). First of all, turn on all errors in your php.ini file and display them: error_reporting = E_ALL display_errors = On So you can see your errors. That should help you a little bit. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. js*******@attglobal.net ================== May 29 '07 #7

### This discussion thread is closed

Replies have been disabled for this discussion.