Missing Argument 1 for PHP

Missing Argument 1 for PHP thumbnail
Programmers should try to cover all scenarios to avoid error conditions.

PHP is a programming language usually used for programming dynamic Web pages. Regular, or static, Web pages are written in HTML, which is just a formatting language and has no programming elements. PHP pages embed programming code in an HTML template and generate out different content according to calling parameters. PHP code may also include functions, which take parameters to receive data when they are called. Argument is another name for a parameter.

  1. Arguments

    • Arguments follow the name of a function in a list in brackets. When the function is called, it expects values in those arguments. Arguments can be populated either with a value, like a_function(“calling”), or with a variable that has already been given a value, like a_function($a_value) or with a reference to a variable's location in memory, like a_function(&$a_value). A function can be declared to accept a series of arguments, like function a_function ($a_value, $b_value). In error reporting, PHP will not refer to the arguments by their name. So, if there is a problem with the treatment of the a_value variable, the error message will refer to “argument 1” rather than “a_value.”

    Argument Status

    • If a function has been written to accept arguments, it has to be called with arguments in brackets after the function name. The arguments passed to the program have to be the same as the number of arguments the program was written to accept. The arguments do not have to have the same name when the function is called to the names used for the arguments when the function was created. Many programmers do this, and many examples show the same name used for the declaration as for the implementation. To avoid confusion it's better to create a naming convention and use a different system for the declaration of arguments as is used for global variables, which will be used to give arguments values when the function is called.

    Error States

    • An error message about missing argument 1 means that the function was called without any values for the parameters. The function may require more than one argument, but if the first one has no value (meaning none have) then the program will stop running with a message about argument 1. It won't reach the point of giving a status message about any of the other arguments in the function call.

    Solution

    • A user of a PHP program receiving this error message has few options. The function reporting the error is likely to be embedded deep inside the program and so it isn't enough to advise that the function should be called with a value, because that user never “called the function” but just used the program. Programmers should put in default values for arguments where possible. This removes the possibility of this error occurring.

Related Searches:

References

  • Photo Credit Photos.com/PhotoObjects.net/Getty Images

Comments

Related Ads

Featured