nospoon Posted January 12, 2006 Share Posted January 12, 2006 a PHP n00b here, having a little trouble, and can not seem to understand why this message is generating:Warning: Missing argument 1 for myclass() in C:\Program Files\xampp\htdocs\class.php on line 51: <?php2: 3: class myClass4: {5: function myClass( $x )6: {7: $this->setName( $x );8: }9:10: function setName( $n )11: {12: $this->name = $n;13: }14:15: function getName()16: {17: return $this->name;18: }19:20: function displayMessage()21: {22: echo "Hello! My name is ".$this->getName().'.';23: }24:25: var $name = "Matt";26: }27:28: $mc = new myClass();29: $mc->displayMessage();30:31: echo "<br>";32: $mc->setName( "Julie" );33: $mc->displayMessage();34:35: ?>Full output was:Warning: Missing argument 1 for myclass() in C:\Program Files\xampp\htdocs\class.php on line 5Hello! My name is .Hello! My name is Julie.Thanks Link to comment Share on other sites More sharing options...
nospoon Posted January 15, 2006 Author Share Posted January 15, 2006 No one knows? It should be an easy one for those seasoned PHPers Link to comment Share on other sites More sharing options...
nospoon Posted January 16, 2006 Author Share Posted January 16, 2006 Nevermind I figured it out. Stepped away from C/C++ for a year and my brain is mush. Handy tip, always keep some sort of project ongoing to keep it fresh! Link to comment Share on other sites More sharing options...
Alanoll Posted January 17, 2006 Share Posted January 17, 2006 well, for those who come across this later...it's because he instantiated the class, but the constructor wanted an argument and he didn't specify a default one.one easy fix would befunction myClass( $x = "" )That way, if you don't specify an argument to pass, it SHOULD then see that it's defined in the function already. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now