- Install PHP, optionally with MySQL/Apache:
- Install Composer -- https://getcomposer.org/
- Choose an example problem from the below list you want to work on.
- Use libraries you've never used before!
- Regroup at the end to discuss what you tried and learned.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Sample | |
{ | |
private $name; | |
// Name is required! | |
public function __construct($name) { | |
$this->setName($name); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Abort script if any command encounters an error | |
set -e | |
current_branch="$(git rev-parse --abbrev-ref HEAD)" | |
repo_root="$(git rev-parse --show-toplevel)" | |
# Get dir where this script lives | |
DIR="$( cd "$( dirname "$0" )" && pwd )" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Open text files from Iterm2 in PhpStorm by command+clicking on it | |
# You will need the Remote call plugin in PhpStorm - https://plugins.jetbrains.com/plugin/6027 | |
# And of course curl | |
# wget this and chmod +x it | |
# then move it to somwhere convenient in your path (such as /usr/local/bin) | |
# With respects to https://gist.github.com/trinitronx/f59a8308d42d71fdba41 for the basis for this | |
# iterm_open_with - open a URL, file from CWD, full path, or path with linenumber in default app or PhpStorm if text file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function some_old($fn) { | |
// Must remove $fn to use remaining args as variadic | |
$variadicArrays = array_slice(func_get_args(), 1); | |
// $variadicArrays is an "implicit" argument because it's not defined in the signature | |
var_dump($variadicArrays); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class User { | |
private $firstname; | |
private $lastname; | |
public function __construct($f, $l) { | |
$this->firstname = $f; | |
$this->lastname = $l; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$range = range(1,100); | |
$numbers = array_filter($range, function ($num) { | |
return $num % 3 !== 0 && $num % 5 !== 0; | |
}); | |
$fizz = array_filter($range, function ($num) { | |
return $num % 3 === 0 && $num % 5 !== 0; | |
}); | |
$buzz = array_filter($range, function ($num) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BuildReport | |
{ | |
private function getColumnHeaders() | |
{ | |
// Why do you need array keys if this array is private details? | |
// It's never exposed outside this class so you have full control of its format | |
return [ | |
['id' => 'first_name', 'label' => 'First Name'], | |
['id' => 'last_name', 'label' => 'Last Name'], | |
['id' => 'department', 'label' => 'Department'], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* PHP 5.6 example of "Functional Options" as presented by Rob Pike | |
* in his article "Self-referential functions and the design of options" | |
* http://commandcenter.blogspot.com.au/2014/01/self-referential-functions-and-design.html | |
*/ | |
namespace Mailer { | |
class Mailer { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace My; | |
class MonologErrorEmailPrototype | |
{ | |
private $fromAddress; | |
private $toAddress; | |
private $host; | |
private $env; |
NewerOlder