/    Sign up×
Community /Pin to ProfileBookmark

missing argument

Hi – I’m getting missing argument warnings, ie:

Warning: Missing argument 1 for Search::search()

on the following code, but can’t work out why (the code seems to work fine).

[CODE]
class Search
{
public function search($type)
{
//my code
}
}
[/CODE]

… which is called by…

[CODE]
$searchCar = new Search();
$searchCar->search(“quick”);
[/CODE]

Obviously I could just switch the PHP warnings off, but I’m just interested to know what’s actually going wrong here!

Thanks for any help possible!

Nick

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@SrWebDeveloperMar 17.2010 — Never disable warnings - especially in development environments, you want to see all warnings and errors. In production environments it's plain old lazy technique. It's good you asked and are willing to learn how to do it the *right* way. Bravo.

As to your issue:

The method requires one argument because you specified $type in your class [U]constructor[/U]. When initiating the class object, you didn't pass any argument at all to the constructor. Methods with the same name as the class are constructors.

Either pass an argument when initiating or change you class to use $type="" which sets a default value (empty string in this case) for the argument if the argument is left out when initiated. Just like you'd do for any function, it's no different in any method in a class via OOP.

-jim
Copy linkTweet thisAlerts:
@sloLearnerauthorMar 17.2010 — That's great, thanks so much Jim!
×

Success!

Help @sloLearner spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...