nospoon Posted January 12, 2006 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
nospoon Posted January 15, 2006 Author Posted January 15, 2006 No one knows? It should be an easy one for those seasoned PHPers
nospoon Posted January 16, 2006 Author 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!
Alanoll Posted January 17, 2006 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.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now