Comments (2)
These checks exist in order to ensure that this user land library triggers the exact same error messages as the function in core PHP. This passes the same tests that are implemented in core, so they have identical functionality.
On Thu, May 8, 2014 at 5:49 AM, Taai [email protected] wrote:
First of all - great job! 😉
Why do you need to check the count of the arguments at all? As I know, PHP will throw an error, if there are less parameters given than required, just don't allow the arguments be optional (as in the manual they are not)! This can be written like this:<?php // function array_column($input = null, $columnKey = null, $indexKey = null) function array_column(array $input, $columnKey, $indexKey = null) { // ... // !!! Now you can get rid of this code too: if ($argc < 2) { trigger_error("array_column() expects at least 2 parameters, {$argc} given", E_USER_WARNING); return null; } if (!is_array($params[0])) { trigger_error('array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given', E_USER_WARNING); return null; } // ... }
Reply to this email directly or view it on GitHub:
#4
from array_column.
I took a closer look at your comment when I got to a computer. :-)
You're correct that PHP will complain if less parameters are given than required, but it won't give the same exact error messages as the code in core generates. That's why these checks are in here to explicitly trigger the same error messages.
As for an error occurring if $params[0]
is not set, it should always be set, and the check for if ($argc < 2)
above ensures this.
Thanks for taking time to investigate the code, though. I really appreciate it, and I'm glad you find this useful.
from array_column.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from array_column.