{"id":3358,"date":"2014-03-23T11:23:21","date_gmt":"2014-03-23T11:23:21","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/23\/array-map-function-error-collection-of-common-programming-errors\/"},"modified":"2014-03-23T11:23:21","modified_gmt":"2014-03-23T11:23:21","slug":"array-map-function-error-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/23\/array-map-function-error-collection-of-common-programming-errors\/","title":{"rendered":"Array Map Function Error-Collection of common programming errors"},"content":{"rendered":"<p>Anonymous functions were introduced in 5.3.0, so if you have an older version of PHP, you&#8217;ll run into this error. Another way to do what you&#8217;re doing is it to use <code>create_function()<\/code>:<\/p>\n<pre><code>array_map(create_function('$v', 'return \"\\'\" . mysql_real_escape_string($v) . \"\\'\";')\n           , $yourArray)\n<\/code><\/pre>\n<p>But a far better alternative would be to use PDO and parameterized queries:<\/p>\n<pre><code>\/\/ example:\n$sth = $dbh-&gt;prepare('INSERT INTO your_table\n                          (activation_status, first_name, last_name)\n                             VALUES (?, ?, ?)');\n\n$params = array($activation_status, $_POST['first_name'], $_POST['last_name']);\n$sth-&gt;execute($params);\n<\/code><\/pre>\n<p>Easier, cleaner and universally understood. Your parameters will be automatically escaped.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Anonymous functions were introduced in 5.3.0, so if you have an older version of PHP, you&#8217;ll run into this error. Another way to do what you&#8217;re doing is it to use create_function(): array_map(create_function(&#8216;$v&#8217;, &#8216;return &#8220;\\'&#8221; . mysql_real_escape_string($v) . &#8220;\\'&#8221;;&#8217;) , $yourArray) But a far better alternative would be to use PDO and parameterized queries: \/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3358","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3358"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3358\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}