Oh, hey guys, I was wondering: Where can I find information about how to do PHP programming projects with multiple programmers? I've always coded by myself, but I might have some other programmers helping me in the near future. I have no idea how to work with other programmers =\
The better I get at programming, the more I appreciate arrays. Handy dandy things they are.
one important thing is to choose a source code control system you like and that provides good team support, such as Git.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
+1 for git. The next thing to be concerned with is assignments, no 2 people should be working on the same file(s) at the same time as this can cause serious headaches when merging changes together.
Threads are one of several technologies that make it possible to execute multiple code paths concurrently inside a single application. Although newer technologies such as operation objects and Grand Central Dispatch (GCD) provide a more modern and efficient infrastructure for implementing concurrency, OS X and iOS also provide interfaces for creating and managing threads.
I ran across something that I've never seen before. It's on line 4. How does that code work? Is it similar to when I do return ($a < $b) ? TRUE:FALSE?
PHP Code:
<?php foreach ($_POST as $key => $value) { // assign to temporary variable and strip whitespace if not an array $temp = is_array($value) ? $value : trim($value); //line 4 // if empty and required, add to $missing array if (empty($temp) && in_array($key, $required)) { $missing[] = $key; } elseif (in_array($key, $expected)) { // otherwise, assign to a variable of the same name as $key ${$key} = $temp; } }
This code was written to find empty fields in a form.
Last edited by evenstar7139; 04-14-2013 at 07:58 PM.
The better I get at programming, the more I appreciate arrays. Handy dandy things they are.
I ran across something that I've never seen before. It's on line 4. How does that code work? Is it similar to when I do return ($a < $b) ? TRUE:FALSE?
PHP Code:
<?php foreach ($_POST as $key => $value) { // assign to temporary variable and strip whitespace if not an array $temp = is_array($value) ? $value : trim($value); //line 4 // if empty and required, add to $missing array if (empty($temp) && in_array($key, $required)) { $missing[] = $key; } elseif (in_array($key, $expected)) { // otherwise, assign to a variable of the same name as $key ${$key} = $temp; } }
This code was written to find empty fields in a form.
Yes, it's a shorthand ternary..
$temp = $value (if value is array) if its not array, trim the whitespace from value.
edit.. $temp = if statement ? true do this : false do this
#1 I heard that MySQL's charset is important when using mysqli::real_escape_string(); What charset should I be using if my site is all in English? UTF-8?
#2 Also, PHPMyAdmin is saying the charset is "UTF-8 Unicode (utf8)" but if I do print_r($mysqli->get_charset()) in a script, it says it's latin1. Which one will mysqli::real_escape_string() use?
The better I get at programming, the more I appreciate arrays. Handy dandy things they are.
After connecting to your DB and before doing anything else, submit this query:
Code:
SET NAMES 'utf8' COLLATE 'utf8_unicode_ci'
This lets MySQL know you'll be "talking UTF-8" to it from this point on in the session. Since the MySQL "real" escape functions in PHP actually call the MySQL DB's API, that should take care of it for you.
Of course, if you're using MySQLi, you should seldom, if ever, need to use the PHP escape function, since you're using prepared statements with bound parameters, right?
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
#2 I'm torn on whether to use prepared statements or not. Some people tell me they can't live without them, others tell me they hate them because they're slower than regular queries. In the past I have had problems with slow queries bogging down my server (I was not using prepared statements) and that experience has left me speed-conscious. So, currently I am leaning away from prepared statements. However, if you would like to argue in favor of me using prepared statements, I will consider what you say.
The better I get at programming, the more I appreciate arrays. Handy dandy things they are.
#1: If you can modify the MySQL config to default to those settings, then no. It's very low overhead, though.
#2: We use prepared statements all the time at work (via PDO connecting to a PostgreSQL DB), and I have no evidence it's a noticeable performance bottleneck (if at all). Poorly configured tables (in particular with regard to proper use of indexes) and inefficient SQL will be a much, much, much bigger issue. I believe in coding first for clarity, maintainability, re-usability, and security; not worrying about a millisecond here and a microsecond there (hardware is fast and relatively cheap these days). Don't worry unduly about optimization* until you know you have a problem, and then address it by testing and metering to find out where the primary issues are and addressing them then.
__________
* Yes, you want to avoid obviously stupid things like foreach() loops that repeat the same query over and over when you could do it with one query instead. When you see optimization opportunities that do not conflict unduly with your other coding objectives, then by all means use them -- but also be aware there is a lot of questionable info out there about how inefficient one technique is over another, often not supported with any empirical measurements
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
#1 Has PHP's implementation of regular expressions changed since 2007?
#2 I know somebody who is learning to do regular expressions with preg_match(). I would like to link her to a tutorial that I used in the past and found easy to follow. However, it was written in 2007. This is it: http://weblogtoolscollection.com/regex/regex.php Does anything jump out at you as outdated or inaccurate?
#3 Should I always do: if (preg_match('regex here', $str) === 0) instead of: if (!preg_match('regex here', $str))
The better I get at programming, the more I appreciate arrays. Handy dandy things they are.
Bookmarks