The conclusion of articles takes place on two pages, 1 - preview blocks, which is the transition to opred. article, and 2 - a specific article, which uses two arguments.

PHP:

function getNews ($limit, $id) { global $mysqli; connectDB(); if ($id) $where = "WHERE `id` = ".$id; $result = $mysqli -> query("SELECT * FROM `news` $where ORDER BY `id` DESC LIMIT $limit"); closeDB(); if (!$id) return resultToArray($result); else return $result->fetch_assoc(); } 

Both pages work, and the warning is on the one where only one argument is used.

Warning: Warning: Missing argument 2 for getNews (), called in W: \ domains \ dszorenka \ news.php on line 6 and defined in W: \ domains \ dszorenka \ functions \ functions.php on line 14

In fact, it seems to me that it checks to the function code, and that it does not check for the existence of an argument inside it does not care. There may really be a wrong code.

  • 2
    But did not you try to read the primer on PHP first? Section "default functions / arguments". - PinkTux
  • 2
    And you don’t rightly care why it should be worried about something inside if you break the signature? - vp_arth
  • I switched to PHP a maximum of a month ago, I did not even read all the starting information. The main reason for this is the similarity of syntax with C #, where I have a little more experience) - Escaper

1 answer 1

If you want to make an optional parameter, you need to specify a default value, for example, false :

 function getNews ($limit, $id = false) { ... } 
  • Thank you very much. I will mark a mistake for myself and try to remember this kind of situation) - Escaper
  • @Escaper Our site is different from social networks. It helps to solve applied problems. Therefore, we use comments only on the case - to clarify the problem, to give constructive criticism or add useful information. To thank the author of the answer, vote for the answer or mark it as a decision. ru.stackoverflow.com/help/someone-answers - Crantisz