├── .editorconfig ├── .github ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── README.md ├── generate └── test.php ├── .gitignore ├── .travis.yml ├── 404.md ├── CNAME ├── LICENSE ├── README.md ├── _config.yaml ├── _install ├── README.md ├── alpine │ ├── apache.md │ ├── lighttpd.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ └── postgresql.md ├── arch │ ├── apache.md │ ├── lighttpd.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ └── postgresql.md ├── centos │ ├── apache.md │ ├── lighttpd.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ └── postgresql.md ├── debian │ ├── apache.md │ ├── lighttpd.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ └── postgresql.md ├── development.md ├── fedora │ ├── apache.md │ ├── lighttpd.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ └── postgresql.md ├── freebsd │ ├── apache.md │ ├── lighttpd.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ └── postgresql.md ├── linux-build.md ├── mac │ ├── apache.md │ ├── lighttpd.md │ ├── mamp.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ ├── postgresql.md │ └── xampp.md ├── rhel │ ├── apache.md │ ├── lighttpd.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ └── postgresql.md ├── ubuntu │ ├── apache.md │ ├── lighttpd.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ └── postgresql.md ├── windows-build.md └── windows │ ├── apache.md │ ├── composer.md │ ├── easyphp.md │ ├── mamp.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── php.md │ ├── postgresql.md │ ├── wpnxm.md │ └── xampp.md ├── c ├── README.md ├── arrays.md ├── basics.md ├── binary-files.md ├── coding-style.md ├── editors.md ├── files.md ├── functions.md ├── intro.md ├── operators.md ├── php-extensions.md ├── see-also.md ├── strings.md ├── structs.md └── variables.md ├── docker ├── README.md ├── alpine.md ├── build.md ├── certbot.md ├── composer.md ├── intro.md ├── permissions.md ├── php-extensions.md ├── recipes.md └── usage.md ├── faq ├── README.md ├── db │ ├── README.md │ ├── files.md │ ├── mongodb-vs-mysql.md │ ├── mysql-functions.md │ ├── mysqli-or-pdo.md │ └── orm.md ├── interop │ ├── README.md │ └── editor-ide.md ├── intro │ ├── README.md │ ├── books.md │ ├── core-vs-vanilla.md │ ├── dollar-sign.md │ ├── hosting.md │ ├── php7.md │ ├── what-is-php.md │ └── why-php.md └── misc │ ├── README.md │ ├── browser-detection.md │ ├── certification.md │ ├── crawling.md │ ├── desktop-applications.md │ ├── email.md │ ├── face-detection.md │ ├── get-vs-post.md │ ├── headers-already-sent.md │ ├── how-to-google.md │ ├── increase-file-upload-size.md │ ├── ip.md │ ├── isp.md │ ├── packages.md │ ├── pretty-urls.md │ ├── professions.md │ ├── projects.md │ ├── scraping.md │ ├── screenshot.md │ ├── single-vs-double-quotes.md │ ├── sms.md │ ├── structure.md │ ├── templating.md │ ├── undefined-variable-index-notice.md │ ├── variables.md │ ├── warning-include-require-failed-stream.md │ └── wildcard-subdomains.md ├── interop ├── README.md ├── assets.md ├── atom.md ├── benchmarks.md ├── git.md ├── intro.md ├── make.md ├── nopaste.md └── vagrant.md ├── js ├── README.md ├── debugging.md └── intro.md ├── linux ├── README.md └── alpine.md ├── misc ├── README.md ├── api │ ├── README.md │ ├── intro.md │ ├── rest.md │ └── soap.md ├── async.md ├── deployment.md ├── ecommerce │ ├── README.md │ ├── intro.md │ ├── magento │ │ ├── README.md │ │ └── about-magento.md │ └── shopware │ │ ├── README.md │ │ └── about-shopware.md ├── frameworks │ ├── README.md │ ├── cakephp.md │ ├── codeigniter.md │ ├── create-your-own-framework.md │ ├── frameworks.md │ ├── laravel.md │ ├── symfony.md │ ├── yii.md │ └── zendframework.md ├── licenses.md ├── packages │ ├── README.md │ ├── cms.md │ ├── composer.md │ ├── excel.md │ ├── image-libraries.md │ ├── packages.md │ ├── pagination.md │ ├── payment-gateways.md │ └── pdf.md ├── quality │ ├── README.md │ ├── bdd.md │ ├── code-quality.md │ ├── debugging.md │ └── testing.md └── versions.md ├── php ├── README.md ├── appendices │ ├── README.md │ ├── best-practices.md │ ├── coding-style.md │ ├── criticism.md │ └── evolution.md ├── community │ ├── README.md │ ├── conferences.md │ ├── elephpant.md │ ├── groups.md │ └── podcasts.md ├── ext │ ├── README.md │ ├── date-time.md │ ├── db │ │ ├── README.md │ │ ├── database-vs-filesystem.md │ │ ├── intro.md │ │ └── pdo.md │ ├── intro.md │ ├── phar.md │ ├── regex.md │ └── sessions │ │ ├── README.md │ │ └── intro.md ├── intro │ ├── README.md │ ├── basics.md │ ├── editors.md │ ├── installation.md │ └── start.md ├── ref │ ├── README.md │ ├── constants.md │ ├── control-structures.md │ ├── cookies.md │ ├── errors.md │ ├── exceptions.md │ ├── functions.md │ ├── generators.md │ ├── namespaces.md │ ├── oop │ │ ├── README.md │ │ ├── abstract-classes.md │ │ ├── anti-patterns.md │ │ ├── autoloading.md │ │ ├── design-patterns │ │ │ ├── README.md │ │ │ ├── abstract-factory.md │ │ │ ├── adapter.md │ │ │ ├── bridge.md │ │ │ ├── builder.md │ │ │ ├── chain-of-responsibility.md │ │ │ ├── command.md │ │ │ ├── composite.md │ │ │ ├── decorator.md │ │ │ ├── dependency-injection.md │ │ │ ├── facade.md │ │ │ ├── flyweight.md │ │ │ ├── interpreter.md │ │ │ ├── intro.md │ │ │ ├── iterator.md │ │ │ ├── lazy-loading.md │ │ │ ├── mediator.md │ │ │ ├── memento.md │ │ │ ├── mock-object.md │ │ │ ├── null-object.md │ │ │ ├── object-pool.md │ │ │ ├── observer.md │ │ │ ├── prototype.md │ │ │ ├── proxy.md │ │ │ ├── servant.md │ │ │ ├── singleton.md │ │ │ ├── state.md │ │ │ ├── strategy.md │ │ │ ├── template-method.md │ │ │ ├── type-tunnel.md │ │ │ └── visitor.md │ │ ├── dic.md │ │ ├── intro.md │ │ ├── iterators.md │ │ └── solid.md │ ├── operators.md │ ├── overview.md │ ├── predefined-variables.md │ ├── references.md │ ├── sessions.md │ ├── types │ │ ├── README.md │ │ └── arrays.md │ └── variables.md └── sapi │ ├── README.md │ ├── apache.md │ ├── cgi.md │ ├── cli.md │ ├── embed.md │ ├── fpm.md │ ├── litespeed.md │ └── phpdbg.md ├── security ├── README.md ├── code-protection.md ├── configuration.md ├── cryptography.md ├── intro.md ├── passwords.md ├── sql-injection.md ├── ssl.md └── uploading.md └── tips ├── README.md ├── arrays ├── 01-json-force-object.md └── README.md ├── composer ├── 01-performance.md └── README.md ├── datetime ├── 01-copyright-year.md ├── 02-datetime.md ├── 03-easter.md └── README.md ├── oop ├── 01-visibility.md └── README.md ├── strings ├── 01-emails.md └── README.md ├── style ├── 01-ifs.md └── README.md └── unicorns ├── 01-comments.md ├── 02-dir.md ├── 03-haystack-needle.md ├── 04-ternary-operator.md └── README.md /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | tab_width = 4 14 | 15 | [*.yml] 16 | indent_style = space 17 | indent_size = 2 18 | 19 | [.github/generate] 20 | indent_style = space 21 | indent_size = 4 22 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of conduct 2 | 3 | This project is part of the [PHP.earth](https://php.earth) group which follows a 4 | [code of conduct](https://conduct.php.earth) to guarantee a welcoming, safe, 5 | inclusive, and harassment-free environment for anyone. 6 | -------------------------------------------------------------------------------- /.github/README.md: -------------------------------------------------------------------------------- 1 | # PHP.earth documentation 2 | 3 | [](https://travis-ci.org/phpearth/docs) 4 | 5 |
After the two linebreaks HTTP response output is defined.
41 | ``` 42 | 43 | In above case first three lines are HTTP headers and after two line breaks output is defined. When PHP script receives the first 44 | output (html, output from `echo` function etc) it will also flush all collected headers so far in the script procedure. Afterwards 45 | it can send all the output it wants however adding other HTTP headers will be impossible from there on. 46 | 47 | 48 | ## Checklist of possible causes and how to fix it 49 | 50 | * Whitespace or other ouput before the starting `` tag. 51 | 52 | ```php 53 | ` sections prior to `id}"; 59 | ``` 60 | 61 | Variable interpolation with curly braces can also contain complex expressions within accessors. 62 | 63 | **Example:** 64 | 65 | ```php 66 | echo "Value is {$arr[max($min, $max)]}"; 67 | ``` 68 | 69 | ### [Heredoc](http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc) 70 | 71 | - Works like double quoted strings. 72 | 73 | - It starts with `<<<`. 74 | 75 | - After this operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation. 76 | 77 | - You don't need to escape quotes in this syntax. 78 | 79 | 80 | ### [Nowdoc](http://php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc) (since PHP 5.3.0) 81 | 82 | - Works essentially like single quoted strings. 83 | 84 | - The difference is that not even **single quotes** or **backslashes** have to be escaped. 85 | 86 | - A nowdoc is identified with the same `<<<` sequence used for heredocs, but the identifier which follows is enclosed in single quotes, e.g. `<<<'EOT'`. **No parsing is done in nowdoc.** 87 | 88 | 89 | ### Credit 90 | 91 | - [Peter Ajtai](http://stackoverflow.com/users/186636/peter-ajtai) - [Stackoverflow Question](http://stackoverflow.com/a/3446286) 92 | -------------------------------------------------------------------------------- /faq/misc/sms.md: -------------------------------------------------------------------------------- 1 | # How to send SMS with PHP? 2 | 3 | Sending SMS (**S**hort **M**essage **S**ervice) with PHP application is done 4 | for multiple purposes. For example, many security enhancements are integrating 5 | multi-factor authentication system where you can additionally identify user by 6 | mobile device, retrieve forgotten passwords or similar. Other common usages 7 | are sending marketing messages, or notifing users about different events and 8 | similar. 9 | 10 | ## Sending SMS via gateway 11 | 12 | The diagram below explains a simplified SMS sending flow where PHP application 13 | communicates with a SMS gateway. Gateway converts and forwards received data to 14 | SMS center (SMSC). SMSC routes data to mobile device (end user). 15 | 16 |  17 | 18 | Most common and simple to integrate usage in PHP applications is using an SMS API. 19 | 20 | ## Sending SMS via email carriers 21 | 22 | Another, less common and less stable option to send SMS is using an email from 23 | particular carrier. SMS is sent by sending an email to certain address with 24 | predefined email data. 25 | 26 | ## See also 27 | 28 | * [gnokii](https://www.gnokii.org/) - Allows you to communicate with the phone. 29 | * [Kannel](http://www.kannel.org/) - Open Source WAP and SMS gateway. 30 | * [Nexmo](https://www.nexmo.com/) - API for sending text messages. 31 | * [PHP Classes](http://www.phpclasses.org/search.html?words=sms&go_search=1) - Several 32 | solutions to send SMS with PHP. 33 | * [SMS Gateway](https://en.wikipedia.org/wiki/SMS_gateway) 34 | * [SMS Gateway Android](https://smsgateway.me/) - Turn your Android phone into a 35 | SMS Gateway. 36 | * [PlaySMS](https://playsms.org) - Free and Open Source SMS Gateway written in 37 | PHP based on Gammu SMSD service. 38 | * [Twillio](https://www.twilio.com/) - API for sending text messages. 39 | * [List of free email to SMS carriers](http://www.emailtextmessages.com) 40 | * Tutorials: 41 | * [Envato Tuts+](http://code.tutsplus.com/tutorials/how-to-send-text-messages-with-php--net-17693) - How 42 | to Send Text Messages with PHP. 43 | * [SitePoint](http://www.sitepoint.com/implement-two-way-sms-with-php/) - Implement 44 | Two-way SMS with PHP. 45 | -------------------------------------------------------------------------------- /faq/misc/undefined-variable-index-notice.md: -------------------------------------------------------------------------------- 1 | # How to fix undefined variable/index notice? 2 | 3 | A common notice when working with PHP can be: 4 | 5 | ``` 6 | Notice: Undefined variable: my_var in C:\xampp\htdocs\index.php on line 14 7 | ``` 8 | 9 | or 10 | 11 | ``` 12 | Notice: Undefined index: my_index C:\xampp\htdocs\index.php on line 24 13 | ``` 14 | 15 | ## Why does this happen? 16 | 17 | You have some lines to set a variable or get posted data from a form like this: 18 | 19 | ```php 20 | $my_var = $_POST['myPostData']; 21 | ``` 22 | 23 | Now PHP does not have `$_POST['myPostData']` if there is no POST data being sent 24 | to the Page. This is when these errors come into play. 25 | 26 | ## How to fix "Undefined variable"? 27 | 28 | ```php 29 | $my_var = ""; // Or $my_var = 0; for numbers to make sure the Variable is initialised 30 | //now use isset() 31 | $my_var = isset($_POST['myPostData']) ? $_POST['myPostData'] : ""; 32 | //or empty() 33 | $my_var = !empty($_POST['myPostData']) ? $_POST['myPostData'] : ""; 34 | ``` 35 | 36 | ## How to fix "Undefined index"? 37 | 38 | ```php 39 | //again we have two options here 40 | //via array_key_exists() 41 | $my_var = array_key_exists('my_index', $my_array) ? $my_array['my_index'] : ""; 42 | //or via isset() 43 | $my_var = isset($my_array['my_index']) ? $my_array['my_index'] : ""; 44 | ``` 45 | 46 | Note that `array_key_exists()` returns `true` when array has the specified key ignoring its value 47 | while `isset()` returns `true` only if the specified key exists and is not `null`. 48 | 49 | ```php 50 | $my_array = []; 51 | $my_array['exists'] = null; 52 | var_dump(array_key_exists('exists', $my_array)); 53 | var_dump(isset($my_array['exists'])); 54 | ``` 55 | 56 | So, you should `array_key_exists()` only in situations which `null` values are relevant, 57 | otherwise use `isset()` because it is much faster than `array_key_exists()`. 58 | 59 | ### Output 60 | ``` 61 | bool(true) 62 | bool(false) 63 | ``` 64 | 65 | ## Null coalescing operator 66 | 67 | Since PHP 7 there is also the ?? (or Null Coalescing) Operator available: 68 | 69 | ```php 70 | $my_var = $_POST['myPostData'] ?? ""; 71 | ``` 72 | -------------------------------------------------------------------------------- /faq/misc/warning-include-require-failed-stream.md: -------------------------------------------------------------------------------- 1 | # How to fix failed to open stream warning? 2 | 3 | A common warning when working with PHP can be: 4 | 5 | ``` 6 | Warning: include(myinclude.php): failed to open stream: No such file or directory in myfile.php on line 1 7 | ``` 8 | 9 | ## Why does this happen? 10 | 11 | You have some lines to include a file like this: 12 | 13 | ```php 14 | include 'myinclude.php'; 15 | ``` 16 | 17 | while your folder tree view is like this: 18 | 19 | ``` 20 | /includes/myinclude.php 21 | 22 | index.php 23 | ``` 24 | 25 | Now PHP can not find the file myinclude.php because it is not in the same directory as the index.php. 26 | 27 | ## How to fix this? 28 | 29 | A basic fix for this is setting the appropriate directory. For this example: 30 | 31 | ```php 32 | include 'includes/myinclude.php'; 33 | ``` 34 | 35 | ## What if the included file is in a different subfolder then the including file? 36 | 37 | Sometimes we have a file tree view like this: 38 | 39 | ``` 40 | files/index.php 41 | 42 | includes/myinclude.php 43 | ``` 44 | 45 | in this case a simple 46 | 47 | ```php 48 | include '../includes/myinclude.php'; 49 | ``` 50 | would do the trick, however the best practice for this case is to use script dir centric paths: 51 | 52 | ```php 53 | include __DIR__.'/../includes/myinclude.php'; 54 | ``` 55 | -------------------------------------------------------------------------------- /faq/misc/wildcard-subdomains.md: -------------------------------------------------------------------------------- 1 | # How to manage wildcard subdomains in PHP? 2 | 3 | Wildcard subdomains are used for user specific sites, Deviantart, blogspot.com 4 | are good examples. Usually DNS handles the subdomains depending on A and CNAME 5 | records. 6 | 7 | Using `.htaccess` will give control on incoming traffic (URL translation). 8 | Below `.htaccess` code will redirect any subdomain to PHP page. 9 | 10 | ```apacheconf 11 | RewriteCond %{HTTP_HOST} !^www\.domain\.com 12 | RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com [NC] 13 | RewriteRule ^/?$ /member.php?username=%1 [L] 14 | ``` 15 | 16 | `.htacces` code will forward incoming request to `member.php` with GET method. 17 | So anyone who types `joy.domain.com` will get content of 18 | `domain.com/member.php?username=joy`. By using SQL query you can verify if the 19 | username exists or not. 20 | 21 | ```php 22 | $sth = $dbh->prepare("SELECT * FROM user WHERE username=:username"); 23 | $sth->bindParam(':username', $username, PDO::PARAM_STR); 24 | $sth->execute(); 25 | $result = $sth->fetch(PDO::FETCH_ASSOC); 26 | if ($result) { 27 | // show user data 28 | } else { 29 | // show 404 page 30 | } 31 | ``` 32 | -------------------------------------------------------------------------------- /interop/README.md: -------------------------------------------------------------------------------- 1 | # Interoperability 2 | 3 | * [Atom editor for PHP developers](atom.md) 4 | * [What is GIT?](git.md) 5 | * [Which libraries and resources are recommended for use with PHP?](intro.md) 6 | * [Nopaste list and services to share and run code online](nopaste.md) 7 | * [Vagrant tutorial](vagrant.md) 8 | * [Web assets (images, JavaScript, CSS files)](assets.md) 9 | * [Performance benchmarks and load testing](benchmarks.md) 10 | * [Managing projects with Make and Makefiles](make.md) 11 | -------------------------------------------------------------------------------- /interop/assets.md: -------------------------------------------------------------------------------- 1 | # Web assets (images, JavaScript, CSS files) 2 | 3 | Assets are front end and static files such as CSS stylesheets, JavaScript files, 4 | images and similar. 5 | 6 | There are multiple approaches you can check out when working with these files in 7 | your PHP application. 8 | 9 | Handling these files usually includes installation from 3rd party location (GitHub), 10 | and copying the required files to your publicly accessible folder, such as `web`, 11 | `public_html` and similar. 12 | 13 | After installation you usually also want to minimize JavaScript and CSS files. 14 | 15 | For images maybe you need to create favicons for multiple devices from source 16 | logo of the website and similar. 17 | 18 | * [Assetic](https://github.com/kriswallsmith/assetic) 19 | * [Composer](https://getcomposer.org) 20 | * [Bower](https://bower.io/) 21 | * [BowerPHP](https://bowerphp.org/) 22 | * [Grunt](http://gruntjs.com/) 23 | * [NPM](http://npmjs.com/) and [Gulp](http://gulpjs.com/) 24 | * [Robo](http://robo.li/) 25 | * [Webpack](https://webpack.github.io/) 26 | 27 | Many developers also use approach of developing a project with two separate 28 | repositories - one for back end (PHP application) and one for front end. 29 | 30 | The API points in the back end part are connected with the front end. Maintaining 31 | and scaling to application requirements can be much easier. 32 | 33 | ## Content delivery network (CDN) 34 | 35 | High traffic and complex sites many times also create a separated CDN for serving 36 | these static files. This can improve the performance since the asset is downloaded 37 | only once from a separate location. 38 | 39 | For many open source front end libraries, many times using a publicly available 40 | CDNs is advices since it reduces the required number of requests and traffic for 41 | your application. 42 | 43 | ## See also 44 | 45 | * [Wikipedia: CDN](https://en.wikipedia.org/wiki/Content_delivery_network) 46 | * [Gulp: Refreshment for Your Frontend Assets](http://knpuniversity.com/screencast/gulp) 47 | * [Sitepoint: A PHP Front End Workflow without Node.js](https://www.sitepoint.com/look-ma-no-nodejs-a-php-front-end-workflow-without-node/) 48 | -------------------------------------------------------------------------------- /interop/benchmarks.md: -------------------------------------------------------------------------------- 1 | # Performance benchmarks and load testing 2 | 3 | Benchmarking your application is important to see how the application performs 4 | under heavier traffic and load. 5 | 6 | ## Apache HTTP server benchmarking tool 7 | 8 | Very common benchmarking tool you can use is [ab](https://httpd.apache.org/docs/2.4/programs/ab.html). 9 | 10 | ```bash 11 | ab -c 10 -n 1000 http://localhost/ 12 | ``` 13 | 14 | ### Authentication 15 | 16 | Stage and beta environments can be sometimes closed for public with HTTP authentication. 17 | To pass username and password: 18 | 19 | ```bash 20 | ab -c 10 -n 1000 -A username:password http://beta.example.org/ 21 | ``` 22 | 23 | ## Siege 24 | 25 | [Siege](https://www.joedog.org/siege-home/) is an HTTP load testing and 26 | benchmarking tool. Its source code is available on [GitHub](https://github.com/JoeDog/siege). 27 | 28 | ```bash 29 | siege -c 10 -r 100 -b -i http://localhost 30 | ``` 31 | 32 | ## JMeter 33 | 34 | [Apache JMeter](http://jmeter.apache.org/) is a more feature rich load tester. 35 | 36 | ## Gatling 37 | 38 | [Gatling](http://gatling.io) is a load tester with GUI. 39 | 40 | ## HTTP keep-alive 41 | 42 | [HTTP keep-alive](https://en.wikipedia.org/wiki/HTTP_persistent_connection) or 43 | HTTP persistent connections greatly improve performance. In performance testing 44 | you can enable them and get better results, however these vary from one testing 45 | software to another. Good practice is to disable them and get comparable results 46 | among the above tests. 47 | -------------------------------------------------------------------------------- /interop/intro.md: -------------------------------------------------------------------------------- 1 | # Which are recommended libraries and resources to use with PHP? 2 | 3 | To successfully develop applications here are some recommended development 4 | libraries and resources you will like and can enrich experience. 5 | 6 | * AJAX: 7 | * [Backbone.js](http://backbonejs.org/) - Structure to web applications that 8 | involve JavaScript and data. 9 | * [jQuery](http://jquery.com/) - Useful JavaScript library for easier AJAX, 10 | HTML document traversal and manipulation, event handling, animation etc. 11 | * File upload: 12 | * [Dropzone.js](http://www.dropzonejs.com/) - Drag'n'drop file uploads. 13 | * User interface: 14 | * [Semantic UI](http://semantic-ui.com/) - Framework that helps you create 15 | beautiful, responsive layouts using human-friendly HTML. 16 | -------------------------------------------------------------------------------- /js/README.md: -------------------------------------------------------------------------------- 1 | # JavaScript for PHP developers 2 | 3 | * [Introduction](intro.md) 4 | * [Debugging front end JavaScript](debugging.md) 5 | -------------------------------------------------------------------------------- /js/debugging.md: -------------------------------------------------------------------------------- 1 | # Debugging front end JavaScript 2 | 3 | ## console.log 4 | 5 | A simple and relatively effective way to debug your front end JavaScript code is 6 | to add the `console.log(var)` to parts where you want to check if the output 7 | matches the expected value. Similar technique as adding break points to your 8 | code. 9 | 10 | The `console.log` output is visible in the browser's console: 11 | 12 | For Google Chrome and Mozilla Firefox you can acceess the developer tools by 13 | pressing the `Control+Shift+I` (on Linux and Windows) or `Command+Option+I` (on 14 | Mac), and find the console tab. 15 | 16 | ## Chrome Developer Tools 17 | 18 | As a next a bit more advanced step, Chrome browser has by default integrated 19 | the developer tools to debug front end code more quickly and efficiently. 20 | 21 | ## Regular expressions 22 | 23 | To debug regular expressions on the fly, you can use the online free regex tool 24 | and debugger at [Regex 101](https://regex101.com). 25 | 26 | ## See alo 27 | 28 | * [Debugging JavaScript with Chrome DevTools](https://developers.google.com/web/tools/chrome-devtools/javascript/) 29 | -------------------------------------------------------------------------------- /js/intro.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | To successfully develop applications here are some recommended development 4 | libraries and resources you will like and can enrich experience. 5 | 6 | * JavaScript basics 7 | * [JavaScript.info](http://javascript.info) - modern JavaScript tutorial. 8 | * [Knp University](https://knpuniversity.com/screencast/javascript-es6) - JavaScript 9 | for PHP Geeks:ES6/ES2015 (New JavaScript) 10 | * [MDN: JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference) 11 | * AJAX: 12 | * [Backbone.js](http://backbonejs.org/) - Structure to web applications that 13 | involve JavaScript and data. 14 | * [jQuery](http://jquery.com/) - Useful JavaScript library for easier AJAX, 15 | HTML document traversal and manipulation, event handling, animation etc. 16 | * File upload: 17 | * [Dropzone.js](http://www.dropzonejs.com/) - Drag'n'drop file uploads. 18 | * User interface: 19 | * [Semantic UI](http://semantic-ui.com/) - Framework that helps you create 20 | beautiful, responsive layouts using human-friendly HTML. 21 | * [Awesome JavaScript](https://github.com/sorrycc/awesome-javascript) 22 | * [If we chose our JavaScript Framework like we chose our music…](https://www.sitepen.com/blog/2017/06/13/if-we-chose-our-javascript-framework-like-we-chose-our-music/) - 23 | JavaScript front end frameworks comparison by Sitepen 24 | -------------------------------------------------------------------------------- /linux/README.md: -------------------------------------------------------------------------------- 1 | # Linux 2 | 3 | ## [PHP.earth Alpine Linux repository](alpine.md) 4 | 5 | PHP.earth includes a repository for installing latest PHP packages 6 | and several PECL extensions on Alpine Linux. 7 | -------------------------------------------------------------------------------- /linux/alpine.md: -------------------------------------------------------------------------------- 1 | --- 2 | description: "Alpine repository with PHP 7.2, PHP 7.1, PHP 7.0, and additional packages for elegant PHP development experience" 3 | --- 4 | 5 | # PHP.earth Alpine Linux repository 6 | 7 | This repository includes packages with the latest PHP versions and some most 8 | commonly used PECL extensions for the elegant PHP development experience on 9 | [Alpine Linux](https://alpinelinux.org/). 10 | 11 | ## Quick usage 12 | 13 | On Alpine Linux add a PHP.earth repository and make it trusted: 14 | 15 | ```bash 16 | apk add --no-cache wget ca-certificates \ 17 | && wget -O /etc/apk/keys/phpearth.rsa.pub https://repos.php.earth/alpine/phpearth.rsa.pub \ 18 | && echo "https://repos.php.earth/alpine/v3.7" >> /etc/apk/repositories 19 | ``` 20 | 21 | PHP.earth packages are prefixed with `php7.2`, `php7.1`, and `php7.0`: 22 | 23 | ```bash 24 | apk search --no-cache php7.2* 25 | ``` 26 | 27 | ## Requirements 28 | 29 | * Alpine Linux `3.7` 30 | 31 | ## Detailed instructions 32 | 33 | ### Repository installation 34 | 35 | Let's go through repository installation step by step. Before adding the 36 | repository, add wget and common CA certificates PEM files in case they haven't 37 | been added yet. This will enable downloading files from the HTTPS locations. 38 | 39 | ```bash 40 | apk add --no-cache wget ca-certificates 41 | ``` 42 | 43 | Making the repository trusted is done by downloading the public key: 44 | 45 | ```bash 46 | wget -O /etc/apk/keys/phpearth.rsa.pub https://repos.php.earth/alpine/phpearth.rsa.pub 47 | ``` 48 | 49 | Last step is registering the repository on APK by appending a new line in 50 | `/etc/apk/repositories`: 51 | 52 | ```bash 53 | echo "https://repos.php.earth/alpine/v3.7" >> /etc/apk/repositories 54 | ``` 55 | 56 | ## Sources 57 | 58 | PHP.earth Alpine Linux repository is located on [GitHub](https://github.com/phpearth/alpine). 59 | -------------------------------------------------------------------------------- /misc/README.md: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | 3 | ## [PHP frameworks](/misc/frameworks) 4 | 5 | Using a framework can help speeding up and improving the application. Find out 6 | which framework to learn and how to create your custom framework. 7 | 8 | ## [PHP E-commerce systems](/misc/ecommerce) 9 | 10 | There are quite a lot of existing open source very good solutions for eCommerce 11 | purposes currently available in PHP. 12 | 13 | ## [Packages, libraries and managing dependencies](/misc/packages) 14 | 15 | PHP ecosystem of open source code from various resources. 16 | 17 | ## [API](/misc/api) 18 | 19 | Application programming interfaces 20 | 21 | ## [Code quality and testing](/misc/quality) 22 | 23 | How to test and write quality PHP code. 24 | 25 | ## [How to deploy PHP application](deployment.md) 26 | 27 | Get your application into production. 28 | 29 | ## [PHP versions usage](versions.md) 30 | 31 | Upgrade your PHP. 32 | 33 | ## [Open source licenses](licenses.md) 34 | 35 | What is a license and which license should you pick for your open source project. 36 | 37 | ## [Asynchronous PHP](async.md) 38 | 39 | Asynchronous programming in PHP. 40 | -------------------------------------------------------------------------------- /misc/api/README.md: -------------------------------------------------------------------------------- 1 | # API 2 | 3 | * [What is API?](intro.md) 4 | * [What is REST?](rest.md) 5 | * [What is SOAP?](soap.md) 6 | -------------------------------------------------------------------------------- /misc/api/intro.md: -------------------------------------------------------------------------------- 1 | # What is API? 2 | 3 | [API](https://en.wikipedia.org/wiki/Application_programming_interface), which 4 | stands for "Application programming interface", is a set of routines, 5 | protocols, and tools for building software applications. 6 | 7 | ## Useful tools 8 | 9 | * [Apiary](https://apiary.io) - API Design Stack built for developers. 10 | * [Swagger](http://swagger.io) - Swagger is a simple yet powerful 11 | representation of your RESTful API. 12 | 13 | ## Documenting 14 | 15 | * [ApiBlueprint](https://apiblueprint.org) - A powerful, high-level API 16 | description language for web APIs. 17 | 18 | ## See also 19 | 20 | Useful frameworks, libraries, and reading material for building APIs. 21 | 22 | * [API Platform](https://api-platform.com/) - API-first web framework on top of 23 | Symfony with JSON-LD, Schema.org and Hydra support. 24 | * [Apigility](https://github.com/zfcampus/zf-apigility-skeleton) - An API 25 | builder built with Zend Framework 2. 26 | * [DC4D](http://daycamp4developers.com/previous-meetings/building-apis-developers-will-love-and-use/) - 27 | Building APIs developers will love and use, free video tutorials about APIs. 28 | Registration required though. 29 | * [HAL](https://github.com/blongden/hal) - A HAL (Hypertext Application 30 | Language) builder library. 31 | * [Insomnia](https://insomnia.rest/) - Free REST API client. 32 | * [Negotiation](https://github.com/willdurand/Negotiation) - A content 33 | negotiation library. 34 | * [Undisturbed REST: A Guide to Designing the Perfect API](http://mulesoft.com/restbook) 35 | * [Lumen: The stunningly fast micro-framework by Laravel.](https://lumen.laravel.com/) 36 | * [Slim: Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.](http://www.slimframework.com/) 37 | * [API Security Checklist](https://github.com/shieldfy/API-Security-Checklist) - 38 | Checklist of the most important security countermeasures when designing, testing, and releasing your API. 39 | * [RapidAPI](https://rapidapi.com/) - API marketplace to find, test and connect 40 | to all sorts of APIs. 41 | -------------------------------------------------------------------------------- /misc/api/rest.md: -------------------------------------------------------------------------------- 1 | # What is REST? 2 | 3 | REST stands for "Representational State Transfer." It was claimed by 4 | [Roy Fielding](https://twitter.com/fielding) in his doctor dissertation in 5 | 2000. 6 | 7 | ## What is the difference between REST and RESTful? 8 | 9 | The term RESTful refers to web services implementing such a REST architecture. 10 | 11 | ## See also 12 | 13 | PHP libraries and resources to checkout. 14 | 15 | * [Bullet PHP](http://bulletphp.com/) - A micro framework for building REST 16 | APIs. 17 | * [Hateoas](https://github.com/willdurand/Hateoas) - PHP library to support 18 | implementing representations for HATEOAS REST web services. 19 | * [RESTful APIs, the big lie](http://mmikowski.github.io/the_lie/) - Technical 20 | critique which introduces some issues of REST and how JSON-Pure APIs could do 21 | better, with a [follow-up article](http://mmikowski.github.io/json-pure/). 22 | * [Restler](https://github.com/Luracast/Restler) - A lightweight framework to 23 | expose PHP methods as RESTful web APIs. 24 | * [Fusio](http://fusio-project.org) - Fusio is an open source API management 25 | platform which helps to build and manage REST APIs. 26 | * [Slim](http://www.slimframework.com) - Slim is a PHP micro framework that 27 | helps you quickly write simple yet powerful web applications and APIs. 28 | * [Api Platform](https://api-platform.com) - The ultimate PHP framework to 29 | build modern web APIs. 30 | -------------------------------------------------------------------------------- /misc/api/soap.md: -------------------------------------------------------------------------------- 1 | # What is SOAP and how to use it in PHP? 2 | 3 | [SOAP](https://en.wikipedia.org/wiki/SOAP) (Simple Object Access protocol) is a 4 | protocol specification for web services that exchange information in the form 5 | of an XML Information Set. 6 | 7 | ## See also 8 | 9 | Libraries and reading material to check out. 10 | 11 | * [NuSOAP](http://nusoap.sourceforge.net/) - SOAP Toolkit for PHP. 12 | * [PHP SOAP extension manual](http://php.net/manual/en/book.soap.php) 13 | * [Zend\\Soap](https://github.com/zendframework/zend-soap) - Standalone Zend 14 | SOAP component. 15 | -------------------------------------------------------------------------------- /misc/async.md: -------------------------------------------------------------------------------- 1 | # Asynchronous PHP 2 | 3 | ## What is the difference between synchronous and asynchronous programming? 4 | 5 | *Synchronous programming* is the most common and used way of writing and executing 6 | code. Code is executed statement by statement. Next statements don't get started 7 | until the previous statement is complete. 8 | 9 | In asynchronous programming statements can start to perform before other 10 | statements are completed. Total time is reduced by minimizing the time spent 11 | waiting for operations to complete. 12 | 13 | Main issue with asynchronous methodology is the dependency between the so called 14 | callbacks. 15 | 16 | ## Terminology 17 | 18 | To properly understand and have common grounds on this topic, some of the common 19 | terms will be explained below. 20 | 21 | * **Concurency** 22 | 23 | Concurency is ability of different program elements to be executed any order. 24 | 25 | * **Coroutine** 26 | 27 | Coroutines are program blocks (for example, functions), that can be suspened 28 | and resumed during the program execution. 29 | 30 | ## Asynchronous programming in PHP 31 | 32 | PHP doesn't provide any optimal means for asynchronous programming yet 33 | out-of-the-box. This can be solved using 3rd party PECL extensions or PHP 34 | libraries. 35 | 36 | ## Standards 37 | 38 | The [PHP Asynchronous Interoperability Group](https://github.com/async-interop) 39 | has been formed to propose standards to PHP-FIG one day. 40 | 41 | ## PHP libraries 42 | 43 | * [React PHP](https://reactphp.org/) 44 | 45 | ## PECL extensions 46 | 47 | * [Swoole](https://www.swoole.co.uk) 48 | 49 | ## See also 50 | 51 | Further resources to study the *asynchronous* topic in more details: 52 | 53 | * [PHP Roundtable: Asynchronous PHP](https://www.phproundtable.com/episode/asynchronous-php) 54 | * [elazar/asynchronous-php](https://github.com/elazar/asynchronous-php) - List 55 | of resources for asynchronous programming in PHP. 56 | * [The Magic Behind Async PHP](https://blog.kelunik.com/2017/11/06/magic-behind-async-php.html) 57 | -------------------------------------------------------------------------------- /misc/ecommerce/README.md: -------------------------------------------------------------------------------- 1 | # PHP E-commerce systems 2 | 3 | * [Which eCommerce application should I use or which framework to use for building eCommerce applications?](intro.md) 4 | * [ShopWare](shopware) 5 | * [Magento](magento) 6 | -------------------------------------------------------------------------------- /misc/ecommerce/intro.md: -------------------------------------------------------------------------------- 1 | # Which eCommerce application should I use or which framework to use for building eCommerce application? 2 | 3 | Same question as with frameworks, CMSes and similar open source solutions comes as well with which eCommerce PHP application to use. 4 | 5 | There are quite a lot of existing open source very good solutions for eCommerce purposes currently available in PHP. Choosing the right one 6 | for the project or a right PHP framework for eCommerce depends on your knowledge and project specifics. 7 | 8 | Some of popular eCommerce solutions: 9 | 10 | * [Magento](http://magento.com/) 11 | * [Magento @ PHP.earth](/misc/ecommerce/magento) 12 | * [ShopWare](http://shopware.com/) 13 | * [ShopWare @ PHP.earth](/misc/ecommerce/shopware) 14 | * [OpenCart](http://www.opencart.com/) 15 | * [Prestashop](http://www.prestashop.com/) 16 | * [Sylius](http://www.sylius.org/) 17 | * [Virtuemart](http://virtuemart.net/) 18 | * [ZenCart](http://www.zen-cart.com/) 19 | -------------------------------------------------------------------------------- /misc/ecommerce/magento/README.md: -------------------------------------------------------------------------------- 1 | # Magento 2 | 3 | Magento is an e-commerce system developed by Magento Inc. The development started 4 | in 2007 and is in active development. Magento 2 was released in November 2015. 5 | 6 | ## In this Section 7 | [About Magento](about-magento.md) 8 | -------------------------------------------------------------------------------- /misc/ecommerce/magento/about-magento.md: -------------------------------------------------------------------------------- 1 | # What is Magento? 2 | 3 | Magento is an e-commerce system developed by Magento Inc. The development started 4 | in 2007 and is in active development. Magento 2 was released in November 2015. 5 | 6 | ## Versions 7 | 8 | Magento has three different versions, two of which are paid and one of which is free of cost to use. 9 | 10 | ### Open Source Edition 11 | 12 | Magento Open Source is the free of charge version of the Magento e-commerce platform. 13 | The Open Source Edition can be added upon with paid or free plugin modules (self developed or provided by other developers). 14 | It provides a basic e-commerce system with all you need to operate. 15 | This version doesn't include Hosting. 16 | 17 | ### Magento Commerce Edition 18 | 19 | First released in April 2016, the Magento Commerce Edition is served as a "platform as a service". 20 | In Magento 2, the Commerce Edition has improved architecture and development tools. 21 | 22 | With tools like Magento Business Intelligence, a detailed analysis of your customers, products and promotions can 23 | help you to analyze where your shop needs some adjustments. 24 | 25 | ### Magento Commerce (On-Premises) Edition 26 | 27 | The Magento Commerce (On-Premises) Edition is a derivate of the Open Source Edition and comes with more features and 28 | functionalities then the Open Source Edition as well as technical support for the installation, usage, configuration and 29 | debugging of problems. 30 | 31 | This makes it especially useful for large companies with shops that have a high throughput of customers and orders per day. 32 | The Magento Commerce Edition is developed by the Magento team with the additions which are requested by the users and 33 | third parties. 34 | This version doesn't include Hosting. 35 | 36 | ## Plugins 37 | 38 | Magento has a plugin module system which offers the availability to add to or change Magento's standard behaviour. 39 | 40 | Plugins can be developed by yourself or by third party developers. 41 | 42 | ## Templates/Designs 43 | 44 | For the Frontend part, Magento uses a Model-View-Controller (MVC) Pattern as well as a Model-View-ViewModel (MVVM) Pattern 45 | and the JavaScript library Knockout.js. 46 | -------------------------------------------------------------------------------- /misc/ecommerce/shopware/README.md: -------------------------------------------------------------------------------- 1 | # ShopWare 2 | 3 | ShopWare is an e-commerce system developed by the German "ShopWare AG". The development started 4 | in 2004 and is in active development. 5 | 6 | ## In this Section 7 | [About ShopWare](about-shopware.md) 8 | -------------------------------------------------------------------------------- /misc/ecommerce/shopware/about-shopware.md: -------------------------------------------------------------------------------- 1 | # What is ShopWare? 2 | 3 | ShopWare is an e-commerce system developed by the German "ShopWare AG". The development started 4 | in 2004 and is in active development. 5 | 6 | ## Versions 7 | 8 | ShopWare offers different versions for subscription: 9 | 10 | ### Community Edition 11 | 12 | The community edition is open-source and free to use without any limitation. It has the same 13 | features as the paid versions and can be added upon with free and paid plugins from the community store. 14 | ShopWare doesn't offer any guarantee or maintenance for the community edition 15 | 16 | ### Professional Edition 17 | 18 | The professional edition offers a guarantee by ShopWare as well as support via the developers. It also adds 19 | the otherwise paid plugins "Storytelling" and "Digital Publishing" for emotional shopping. This version 20 | comes with an ERP-System. 21 | 22 | ### Professional Plus Edition 23 | 24 | The professional plus edition comes with all features of the professional edition plus all "premium plugins" 25 | made by the ShopWare developers which add a lot of features for the marketing of your shop. 26 | 27 | ### Enterprise Edition 28 | 29 | The enterprise edition supports high traffic as well as B2B features and a 24/7 developer support with the 30 | option of personal assistance. 31 | 32 | ## Plugins 33 | 34 | ShopWare offers a plugin system with which you can develop your own plugins to alter the shops behaviour 35 | and design as well as adding functionalities. 36 | 37 | Plugins can be developed on your own using PHP, ExtJS/JS/jQuery, Smarty and LESS. Plugins are also available 38 | for free or paid from the ShopWare community store. 39 | 40 | ## Templates/Designs 41 | 42 | For templating, ShopWare uses the templating engine Smarty and for the designing ShopWare uses LESS files, 43 | which are compiled into a minified form. 44 | -------------------------------------------------------------------------------- /misc/frameworks/README.md: -------------------------------------------------------------------------------- 1 | # PHP frameworks 2 | 3 | * [What is a PHP framework and which one should I learn and use?](frameworks.md) 4 | * [How to make your own PHP framework?](create-your-own-framework.md) 5 | * [Cake PHP](cakephp.md) 6 | * [CodeIgniter](codeigniter.md) 7 | * [Laravel](laravel.md) 8 | * [Symfony](symfony.md) 9 | * [Yii](yii.md) 10 | * [Zend Framework](zendframework.md) 11 | -------------------------------------------------------------------------------- /misc/frameworks/cakephp.md: -------------------------------------------------------------------------------- 1 | # CakePHP framework 2 | 3 | [CakePHP](http://cakephp.org/) is a MVC Rapid Development Framework for PHP. 4 | 5 | ## See also 6 | 7 | * [Awesome CakePHP](https://github.com/friendsofcake/awesome-cakephp) - A 8 | curated list of amazingly awesome CakePHP plugins, resources and shiny 9 | things. 10 | * [Friends of CakePHP](http://friendsofcake.com/) - Group of dedicated CakePHP 11 | developers working together to provide the CakePHP community with high 12 | caliber CakePHP plugins and resources. 13 | -------------------------------------------------------------------------------- /misc/frameworks/codeigniter.md: -------------------------------------------------------------------------------- 1 | # CodeIgniter framework 2 | 3 | [CodeIgniter](http://www.codeigniter.com/) is a powerful PHP framework with a 4 | very small footprint, built for developers who need a simple and elegant 5 | toolkit to create full-featured web applications. 6 | 7 | CodeIgniter has a lean MVC framework, with enough capabilities to improve 8 | productivity, while providing for third-party addons/plugins for additional 9 | functionality. 10 | 11 | ## See also 12 | 13 | * [Documentation](http://www.codeigniter.com/user_guide/) - CodeIgniter User Guide. 14 | * [Github](https://github.com/bcit-ci/CodeIgniter) - Codeigniter Repo 15 | * [Download](https://www.codeigniter.com/download)- Codeigniter Download Link 16 | * [Forum](http://forum.codeigniter.com/)-Support & Discuss 17 | -------------------------------------------------------------------------------- /misc/frameworks/create-your-own-framework.md: -------------------------------------------------------------------------------- 1 | # How to make your own PHP framework? 2 | 3 | Building your own framework can be useful for the following reasons: 4 | 5 | * You can learn a lot - advanced design patterns, concepts and software 6 | architecture. 7 | * You know exactly what certain parts of your code do without learning from the 8 | documentation of others. 9 | 10 | However, on the PHP market there are many very high quality open source 11 | frameworks that many projects and organizations use to build software faster 12 | and better. Picking an established open source framework has its benefits: 13 | 14 | * When working in a team, people that already know the open source framework 15 | used by a project can join the project faster. 16 | * Better quality and a lot of bugs that have been identified and fixed, that 17 | your custom framework hasn't been tested for in a many projects yet. 18 | 19 | ## What knowledge you will need to create a decent framework? 20 | 21 | For creating a framework you will have to know OOP, design patterns, ORM, 22 | authentication, MVC (model view controller) and other advanced concepts. 23 | 24 | ## See also 25 | 26 | Here are listed some useful resources and tutorials that can also help you 27 | create your own modern and quality PHP framework. 28 | 29 | * [Building your own framework on top of Symfony components](http://symfony.com/doc/current/create_framework/index.html) - 30 | Build a modern PHP framework on top of quality Symfony components. 31 | * [Frameworkless](https://medium.com/@mmeyer/frameworkless-or-how-i-use-php-bf0b119536ad) - 32 | Tutorial how to create custom framework with Composer and PHP packages and 33 | components. 34 | * [No Framework tutorial](https://github.com/PatrickLouys/no-framework-tutorial) 35 | * [PHP Frameworking](http://phpocean.com/tutorials/back-end/php-frameworking-introduction-part-1/9) - 36 | Introduction to frameworks and how to create your own framework. 37 | * [Modern PHP without framework](https://kevinsmith.io/modern-php-without-a-framework) 38 | -------------------------------------------------------------------------------- /misc/frameworks/laravel.md: -------------------------------------------------------------------------------- 1 | # Laravel framework 2 | 3 | [Laravel](http://laravel.com/) is popular and simple to use component based PHP 4 | framework. 5 | 6 | ## See also 7 | 8 | Some useful resources to check when learning and working with Laravel: 9 | 10 | * [Awesome Laravel](https://github.com/chiraggude/awesome-laravel) - A curated 11 | list of bookmarks, packages, tutorials, videos and other cool resources from 12 | the Laravel ecosystem. 13 | * [Laracasts](https://laracasts.com/) - Laravel video tutorials, free and paid. 14 | * [Laravel News](https://laravel-news.com/) 15 | -------------------------------------------------------------------------------- /misc/frameworks/symfony.md: -------------------------------------------------------------------------------- 1 | # Symfony framework 2 | 3 | [Symfony](http://symfony.com) is a set of reusable PHP components and a framework. 4 | 5 | Best way to get to know Symfony is to go through a 6 | [quick tour](http://symfony.com/doc/current/quick_tour/index.html) - four 7 | chapters, each 10 minutes long. After that, reading the 8 | [documentation](http://symfony.com/doc/current/index.html) is advised and is 9 | the best way to learn it thoroughly. 10 | 11 | Symfony uses bundles for applications and to extend and reuse functionality in 12 | them. A large and vibrant community that has evolved around Symfony provides 13 | bundles for almost anything. They can be found at 14 | [KpnBundles](http://knpbundles.com/). 15 | 16 | You can also get [certified](https://sensiolabs.com/en/symfony/certification.html) 17 | or meet the community at one of the [Symfony events](http://symfony.com/events/). 18 | 19 | ## See also 20 | 21 | Useful resources and tutorials when working with Symfony: 22 | 23 | * [Awesome Symfony](https://github.com/sitepoint/awesome-symfony) - A list of 24 | awesome Symfony bundles, utilities and resources. 25 | * [Knp University](http://knpuniversity.com/) - PHP and Symfony Tutorials (paid 26 | and free). 27 | * [Screenfony](http://www.screenfony.com/) - Symfony tutorials (paid). 28 | * [Symfony2cheatsheet](http://www.symfony2cheatsheet.com/) - Symfony 29 | cheatsheet. 30 | * [Working with Symfony 2 - Tuts+](http://code.tutsplus.com/series/working-with-symfony-2--cms-636) - 31 | A video course about building applications in Symfony. 32 | * [Symfony Tutorial](https://www.cloudways.com/blog/category/applications/symfony/) - 33 | Category for Symfony Tutorial. 34 | * [Symfony Finland](https://www.symfony.fi/) - PHP, Symfony and web development 35 | articles. 36 | -------------------------------------------------------------------------------- /misc/frameworks/yii.md: -------------------------------------------------------------------------------- 1 | # Yii framework 2 | 3 | [Yii](http://www.yiiframework.com/) is a high-performance PHP framework. 4 | 5 | ## Resources 6 | 7 | * [Documentation](http://www.yiiframework.com/doc/) 8 | 9 | ## See also 10 | 11 | * [Introduction to the Yii Framework](http://code.tutsplus.com/articles/introduction-to-the-yii-framework--cms-20948) 12 | * [How to Program With Yii2](http://code.tutsplus.com/series/how-to-program-with-yii2) 13 | * [Yii2 Developer Exchange](http://yii2x.com/) 14 | * [Yii Tutorials](https://www.cloudways.com/blog/category/applications/yii/) 15 | -------------------------------------------------------------------------------- /misc/frameworks/zendframework.md: -------------------------------------------------------------------------------- 1 | # Zend framework 2 | 3 | [Zend Framework](http://framework.zend.com/) - Enterprise and component based 4 | PHP Framework from Zend. 5 | 6 | ## See also 7 | 8 | * [Documentation](http://framework.zend.com/manual/current/en/index.html) - 9 | Zend Framework 2 programmer's reference guide. 10 | * [Zend Framework Certification](http://www.zend.com/en/services/certification/framework) 11 | -------------------------------------------------------------------------------- /misc/licenses.md: -------------------------------------------------------------------------------- 1 | # Open source licenses 2 | 3 | ## What is a license and why should you pick one for your project? 4 | 5 | When open sourcing your code project you should always pick an appropriate license 6 | for it. 7 | 8 | There are a lot of open source licenses available that fit a lot of use cases. 9 | 10 | * MIT License 11 | * [Creative Commons Attribution-ShareAlike 4.0 license](https://creativecommons.org/licenses/by-sa/4.0/legalcode) 12 | 13 | ## See also 14 | 15 | * [Coding Horror blog post](http://blog.codinghorror.com/pick-a-license-any-license/) 16 | * [Choose a license](http://choosealicense.com/) 17 | * [The MIT License, Line by Line](https://writing.kemitchell.com/2016/09/21/MIT-License-Line-by-Line.html) 18 | * [TL;DR Legal](https://tldrlegal.com/) 19 | -------------------------------------------------------------------------------- /misc/packages/README.md: -------------------------------------------------------------------------------- 1 | # Packages, libraries and managing dependencies 2 | 3 | * [What is Composer?](composer.md) 4 | * [What is a CMS and which one should I use?](cms.md) 5 | * [How to work with Excel in PHP?](excel.md) 6 | * [Are there any image manipulation libraries in PHP? Which ones are good?](image-libraries.md) 7 | * [How to add pagination?](pagination.md) 8 | * [What is a payment gateway? How to integrate and use payment gateways in PHP?](payment-gateways.md) 9 | * [How to work with PDF files in PHP?](pdf.md) 10 | * [PHP packages](packages.md) 11 | -------------------------------------------------------------------------------- /misc/packages/image-libraries.md: -------------------------------------------------------------------------------- 1 | # Are there any image manipulation libraries in PHP? Which ones are good? 2 | 3 | Resources and image libraries: 4 | 5 | * [PHP's GD manual](http://php.net/manual/en/book.image.php) - PHP manual about image processing, generation and GD 6 | * [Imagine](https://github.com/avalanche123/Imagine) - PHP 5.3+ Object Oriented image manipulation library 7 | * [Image](https://github.com/Gregwar/Image) - PHP Image library 8 | -------------------------------------------------------------------------------- /misc/packages/pagination.md: -------------------------------------------------------------------------------- 1 | # How to add pagination? 2 | 3 | ## See also 4 | 5 | Some useful libraries and resources to check out: 6 | 7 | * [PagerFanta](https://github.com/whiteoctober/Pagerfanta) - Useful pagination library for PHP. 8 | * [KnpPaginatorBundle](https://github.com/KnpLabs/KnpPaginatorBundle) - Pagination bundle for Symfony2 9 | -------------------------------------------------------------------------------- /misc/packages/payment-gateways.md: -------------------------------------------------------------------------------- 1 | # What is payment gateway? How to integrate and use payment gateways in PHP? 2 | 3 | Payment gateways are e-commerce application service provider services that 4 | authorize credit card payments for e-businesses, online retailers, bricks and 5 | clicks, or traditional brick and mortar. 6 | 7 | Payment gateways link your website to your processing network and merchant account. 8 | In other words they facilitates the transfer of information between a website and 9 | the Front End Processor or acquiring bank. 10 | 11 | Resources and PHP libraries to check out: 12 | 13 | * [PHPLeague Omnipay](https://github.com/thephpleague/omnipay) - a framework 14 | agnostic, multi-gateway payment processing library for PHP 5.3+ 15 | * [TrustPay](https://www.trustpay.eu/) - an international payment gateway 16 | * [PayPal documentation](https://developer.paypal.com/docs/accept-payments/) - a 17 | documentation for processing payments through PayPal 18 | -------------------------------------------------------------------------------- /misc/packages/pdf.md: -------------------------------------------------------------------------------- 1 | # How to work with PDF files in PHP? 2 | 3 | In your application you will often need to create PDF files. For creating PDF files usage of [PHP's PDF functions](http://php.net/manual/en/book.pdf.php) is advised. 4 | 5 | Often this is not enough and you need extra functionalities on top of PHP PDF functions. PHP libraries and resources to check out: 6 | 7 | * [FPDF](http://www.fpdf.org/) - Open Source PHP class for generating PDF documents 8 | * [FPDI](http://www.setasign.com/products/fpdi/about/) - Collection of PHP classes to read pages from PDF 9 | * [PDF libraries on packagist](https://packagist.org/search/?q=pdf) - PDF libraries on packagist 10 | * [PHPPdf](https://github.com/psliwa/PHPPdf) - Pdf and graphic files generator library written in php 11 | * [TCPDF](http://www.tcpdf.org/) - Open Source PHP Class for generating PDF documents 12 | * [Dompdf](https://github.com/dompdf/dompdf) - Open Source HTML layout and rendering engine written in PHP 13 | -------------------------------------------------------------------------------- /misc/quality/README.md: -------------------------------------------------------------------------------- 1 | # Code quality and testing 2 | 3 | * [Writing quality code and code analysis](code-quality.md) 4 | * [How to test PHP code?](testing.md) 5 | * [Behavior driven development?](bdd.md) 6 | * [How to debug PHP code?](debugging.md) 7 | -------------------------------------------------------------------------------- /misc/quality/bdd.md: -------------------------------------------------------------------------------- 1 | # Behavior driven development 2 | 3 | Behavior driven development (BDD) is a software development process that evolved from 4 | TDD. It makes tests more natural by making English sentences that express certain 5 | behavior. It is an outside-in way of developing software, where you make examples 6 | of how the software should behave (feedback from stakeholders being either 7 | clients, your users or you) to achieve certain goals. 8 | 9 | ## StoryBDD 10 | 11 | There are two types of BDD - StoryBDD and SpecBDD. StoryBDD focuses on business 12 | and features. Here is a quick and simplified *example* of a login functionality 13 | based on [Behat](http://docs.behat.org) framework. By communicating with 14 | stackeholders, developers create login *scenario* (or an *example* in BDD): 15 | 16 | ```yaml 17 | Feature: Login 18 | I want to have access to certain page only if I provide 19 | correct username and secret password 20 | 21 | Scenario: Checking username and password 22 | Given I am on a login page "login" 23 | And I provide username "foo" 24 | And I provide password "bar" 25 | When I run "Login" 26 | Then I should see: 27 | """ 28 | Login is successful. 29 | """ 30 | ``` 31 | 32 | This ensures that developers understand how stackeholder want this functionality 33 | to work, and that stackeholders expect this functionality to be implemented like 34 | developers are planning to implement it. 35 | 36 | Instead of writing unit tests like with TDD, the scenario is also your test before 37 | writing the code. 38 | 39 | ## SpecBDD 40 | 41 | The second type of BDD is SpecBDD which focuses on technical behavior of code. 42 | Specifications describe how the certain code should behave. Instead of testing part 43 | of your code, you are describing that part of the code. 44 | 45 | ## See also 46 | 47 | Articles and tools you should check out: 48 | 49 | * Articles: 50 | * [BDD article on Wikipeida](http://en.wikipedia.org/wiki/Behavior-driven_development) 51 | * [Introducing BDD](http://dannorth.net/introducing-bdd/) - Article by Dan North 52 | * [What's in a story, by Dan North](http://dannorth.net/whats-in-a-story/) 53 | * PHP Tools: 54 | * [Codeception](http://codeception.com/) 55 | * [Behat](http://docs.behat.org/) - Behavior Driven Development Framework 56 | for PHP you should check out. 57 | * [Pho](https://github.com/danielstjules/pho) 58 | * [PHPSpec](http://www.phpspec.net/) 59 | * [Kahlan](https://kahlan.github.io/docs/) 60 | -------------------------------------------------------------------------------- /misc/quality/code-quality.md: -------------------------------------------------------------------------------- 1 | # Writing quality code and code analysis 2 | 3 | Beside writing tests, there are more factors that affect the quality of your 4 | code. Let's check some tools for PHP that can improve your code quality. 5 | 6 | ## PhpMetrics 7 | 8 |  9 | 10 | [PhpMetrics][phpmetrics] is a very convenient static analysis tool for your 11 | code and your PHP projects. 12 | 13 | It can be installed with [Composer](https://getcomposer.org/) or by downloading [phar][phar]: 14 | 15 | ```bash 16 | composer global require 'halleck45/phpmetrics' 17 | phpmetrics --report-html=myreport.html /path/of/your/sources 18 | ``` 19 | 20 | PhpMetrics can even interact with [Jenkins][Jenkins] and [Sonar][sonar]. 21 | 22 | After running PhpMetrics from terminal you get an HTML file that looks 23 | something like this: 24 | 25 |  26 | 27 | Some examples of PhpMetrics reports: 28 | 29 | * [CodeIgniter 3.0 PhpMetrics report](http://bl.ocks.org/petk/raw/c5b4da6935d9a8684248/) 30 | * [Symfony 2.6 PhpMetrics report](http://bl.ocks.org/petk/raw/d43726688595f112a419/) 31 | 32 | ## See also 33 | 34 | Other useful tools to check out: 35 | 36 | * [PHP Parser][phpparser] - This is a PHP 5.2 to PHP 7.1 parser written in PHP. Its purpose is to simplify static code analysis and manipulation. 37 | * [PHP QA tools][phpqatools] - List of PHP Quality Assurance tools 38 | * [Jenkins PHP][jenkinsphp] - Template for Jenkins Jobs for PHP Projects 39 | * [PHP Mess Detector][phpmd] - User friendly and easy to configure frontend for the raw metrics measured by [PHP Depend][phpdepend] 40 | * [PHPCheckStyle][phpcheckstyle] - open-source tool that helps PHP programmers adhere to certain coding conventions 41 | * [Qafoo Quality Analyzer](https://github.com/Qafoo/QualityAnalyzer) - Tool helping us to analyze software projects. 42 | * [SensioLabsInsight][SensioLabsInsight] - A quick way to run over 100 quality tests on your code (free version available). 43 | 44 | [phpparser]: https://github.com/nikic/PHP-Parser 45 | [phpmetrics]: http://phpmetrics.org 46 | [phar]: https://github.com/Halleck45/PhpMetrics/raw/master/build/phpmetrics.phar 47 | [jenkins]: http://jenkins-ci.org/ 48 | [sonar]: http://www.sonarqube.org 49 | [phpqatools]: http://phpqatools.org/ 50 | [jenkinsphp]: http://jenkins-php.org/ 51 | [phpmd]: http://phpmd.org/ 52 | [phpdepend]: http://pdepend.org/ 53 | [phpcheckstyle]: https://phpcheckstyle.github.io/ 54 | [SensioLabsInsight]: https://insight.sensiolabs.com/ 55 | -------------------------------------------------------------------------------- /misc/quality/testing.md: -------------------------------------------------------------------------------- 1 | # How to test PHP code? 2 | 3 | Testing code is an important part of development and should not be avoided. It 4 | adds extra time to development but it also improves code quality and saves you 5 | more time when you're adding new features, or refactoring your code without 6 | breaking something. 7 | 8 | You're testing your code already between the development itself without maybe 9 | realizing. When you add some part of code, you either check for the correct 10 | output or response in browser, database etc. However this way not all cases are 11 | considered and it is not repeatable and automated. Soon you need something more 12 | reliable and organized. 13 | 14 | In PHP there are available many testing tools and frameworks. Testing can be 15 | categorized based on the approach. 16 | 17 | ## Test driven development (aka TDD) 18 | 19 | TDD is a software development process in which you repeat very short 20 | development cycles in which you write code that passes or intentionally fails. 21 | 22 | ### Unit testing 23 | 24 | Probably the most used tool and de-facto standard for unit testing in PHP is 25 | the [PHPUnit](https://phpunit.de/) testing framework. It has an awesome manual 26 | so do read it and start using TDD. 27 | 28 | ### Functional testing 29 | 30 | By using tools you create automated tests, where application is actually used 31 | instead of just checking certain parts of code. 32 | 33 | * [Selenium](http://seleniumhq.com/) 34 | * [Mink](http://mink.behat.org/) 35 | * [Codeception](http://codeception.com/) 36 | 37 | ## Behavior driven development (aka BDD) 38 | 39 | Behavior driven development is a software development process that evolved from 40 | TDD. It makes unit tests more natural by making English sentences that express 41 | certain behavior. Read more about PHP focused BDD in the dedicated 42 | [chapter](/misc/quality/bdd.md). 43 | 44 | ## Testing spaghetti code 45 | 46 | What is spaghetti code? 47 | 48 | Spaghetti code is a term for complex unstructured code, which also has lots of 49 | goto statements, exceptions, threads and other unstructured branching 50 | constructs. 51 | 52 | What is Macaroni code? 53 | 54 | Languages all mixed up like mac and cheese. For example, SQL and PHP together. 55 | 56 | ## Why testing code if the application works ok and is in production? 57 | 58 | * Code can be bad and you want to assure it is working ok 59 | * Maybe there is repeating code in different parts of your application 60 | * When you copy/paste code you can break things. We are a human beings and we 61 | all make mistakes. Also bugs might get copied and pasted besides the code. 62 | 63 | ## See also 64 | 65 | * [PHPCI](https://www.phptesting.org/) - Free and open source continuous 66 | integration specifically designed for PHP. 67 | * [Wikipedia](http://en.wikipedia.org/wiki/Test-driven_development) 68 | -------------------------------------------------------------------------------- /php/README.md: -------------------------------------------------------------------------------- 1 | # Vanilla PHP 2 | 3 | PHP is a widely used, popular general-purpose scripting language that is 4 | especially suited to web development and writing command line scripts. 5 | 6 | In this course you will learn how to write PHP code and develop PHP applications. 7 | You will become more confident in your PHP development skills. 8 | 9 | ## [PHP introduction](/php/intro) 10 | 11 | Start with this chapter to get to know PHP, how to install it, which editor to 12 | use, and create your first hello world program. 13 | 14 | ## [PHP language reference](/php/ref) 15 | 16 | Built-in PHP language features and syntax. 17 | 18 | ## [PHP extensions](/php/ext) 19 | 20 | PHP consists of extensions. PHP extension is a self containing module that 21 | provides some particular functionality, such as sessions or accessing databases. 22 | 23 | ## [PHP SAPI modules](/php/sapi) 24 | 25 | **S**erver **A**pplication **P**rogramming **I**nterface - SAPI helps interacting 26 | between the outside world and the PHP/Zend engine. PHP comes with muliple SAPI 27 | modules for using it in command line, with web servers or even embedding it in 28 | other applications. 29 | 30 | ## [PHP community](/php/community) 31 | 32 | Awesome PHP community and PHP user groups. 33 | 34 | ## [Appendices](/php/appendices) 35 | 36 | Additional important chapters to understand and know more about PHP. 37 | -------------------------------------------------------------------------------- /php/appendices/README.md: -------------------------------------------------------------------------------- 1 | # Appendices 2 | 3 | ## [PHP coding style](coding-style.md) 4 | 5 | This chapter will discuss how should you style your PHP code (spaces or tabs, 6 | where to put curly brackets, etc.) 7 | 8 | ## [PHP evolution](evolution.md) 9 | 10 | How it all began and how PHP evolved through time. 11 | 12 | ## [PHP criticism](criticism.md) 13 | 14 | PHP is not perfect. Any language is. This chapter will focus on all the criticism 15 | around PHP language and its ecosystem and how to tackle these issues. 16 | 17 | ## [Best PHP practices](best-practices.md) 18 | 19 | There are many ways to write PHP. This is a collection of best PHP best practices. 20 | -------------------------------------------------------------------------------- /php/appendices/criticism.md: -------------------------------------------------------------------------------- 1 | # PHP criticism 2 | 3 | PHP began 4 | -------------------------------------------------------------------------------- /php/appendices/evolution.md: -------------------------------------------------------------------------------- 1 | # PHP evolution 2 | 3 | Knowing something about [PHP history](http://php.net/history.php) and about who 4 | initially created the PHP language and started the [PHP](http://php.net) 5 | project is interesting information that might help inspire you for developing 6 | something of your own. It might also help you to better understand the current 7 | state of PHP functionality. 8 | 9 | PHP was initially written by **Rasmus Lerdorf**. It all started in 1994 when 10 | Rasmus started working on the very first incarnation of PHP which was a simple 11 | set of Common Gateway Interface (CGI) binaries written in the C programming 12 | language. 13 | 14 | ## See also 15 | 16 | * [PHP Evolution](https://line.do/php-evolution/8oq) - Timeline with important 17 | milestones of PHP evolution. 18 | * [Wikipedia](http://en.wikipedia.org/wiki/PHP) 19 | -------------------------------------------------------------------------------- /php/community/README.md: -------------------------------------------------------------------------------- 1 | # PHP Community 2 | 3 | ## [PHP community and PHP user groups](groups.md) 4 | 5 | What is PHP community and what are PHP user groups. 6 | 7 | ## [PHP conferences](conferences.md) 8 | 9 | Meet some highlighted PHP conferences around the world. 10 | 11 | ## [ElePHPant](elephpant.md) 12 | 13 | PHP uses elephants in their logotypes. Learn what are elephpants and how they 14 | came to be. 15 | 16 | ## [PHP podcasts](podcasts.md) 17 | 18 | Some of the most listened and visited PHP and framework related podcasts. 19 | -------------------------------------------------------------------------------- /php/community/conferences.md: -------------------------------------------------------------------------------- 1 | # PHP conferences 2 | 3 | PHP conferences are PHP specific events, at which established, well known PHP 4 | speakers present their topics and users meet and discuss PHP related topics and 5 | have fun. They occur all over the world in many countries. 6 | 7 | [PHP.net](http://php.net) always updates and announces PHP conferences from all 8 | over the world. You can check the list of current conferences happening in the 9 | [PHP's conference section](http://php.net/conferences/index.php). 10 | 11 | There are some established conferences located in very comfy and easy to visit 12 | locations. 13 | 14 | ## Highlighted PHP conferences 15 | 16 | * **Bulgaria** 17 | * PHP Bulgaria 18 | * http://www.bgphp.org/ 19 | 20 | * **Croatia** 21 | * Web Summer Camp 2017 22 | * http://2017.websummercamp.com/ 23 | 24 | * **Germany** 25 | * International PHP Conference 26 | * https://phpconference.com/en/ 27 | 28 | * **Italy** 29 | * PHP Day 30 | * http://2017.phpday.it/ 31 | 32 | * **Netherlands** 33 | * Dutch PHP 34 | * https://www.phpconference.nl/ 35 | 36 | * LaraCon EU 37 | * https://laracon.eu/2017/ 38 | 39 | * **Romania** 40 | * SymfonyCon Romania 41 | * http://live.symfony.com/ 42 | 43 | * **Serbia** 44 | * PHPSerbia 45 | * http://www.conf2017.phpsrbija.rs/ 46 | 47 | * **USA** 48 | * LaraCon US 49 | * http://laracon.us/ 50 | 51 | * Symfony Live San Francisco 52 | * http://live.symfony.com/ 53 | 54 | * php[cruise]! - Baltimore 55 | * https://cruise.phparch.com/ 56 | 57 | * PHPtek 58 | * https://tek.phparch.com/ 59 | 60 | * Lone Star 61 | * http://lonestarphp.com/ 62 | 63 | There are a lot more. 64 | -------------------------------------------------------------------------------- /php/community/podcasts.md: -------------------------------------------------------------------------------- 1 | # PHP podcasts 2 | 3 | ## PHP related podcasts 4 | 5 | * [Lately in PHP](https://www.phpclasses.org/blog/category/podcast/) 6 | * [PHP Podcasts](https://www.phppodcasts.com/) 7 | * [PHP Roundtable](https://www.phproundtable.com/) 8 | * [PHP Town Hall](https://phptownhall.com/) 9 | * [PHPUgly Podcast](https://phpugly.com/) 10 | 11 | ## PHP framework related podcasts 12 | 13 | * [Laravel News Podcast](https://laravel-news.com/podcast/) 14 | * [Laravel Podcast](http://www.laravelpodcast.com/) 15 | * [Sound of Symfony](http://www.soundofsymfony.com/) 16 | 17 | ## General 18 | 19 | * [/dev/hell](http://devhell.info/) 20 | -------------------------------------------------------------------------------- /php/ext/README.md: -------------------------------------------------------------------------------- 1 | # PHP extensions 2 | 3 | PHP consists of extensions. PHP extension is a self containing module that 4 | provides some particular functionality, such as sessions or accessing databases. 5 | 6 | ## [PHP extensions introduction](intro.md) 7 | 8 | Introduction chapter will introduce the categorization of the PHP extensions, 9 | where they can be found and how you can install them. 10 | 11 | ## [Date and time](date-time.md) 12 | 13 | PHP date extension provides functions and classes for working with dates and 14 | time. 15 | 16 | ## [Sessions](/php/ext/sessions) 17 | 18 | PHP session extension provides functions and classes for persisting data between 19 | requests. Learn more about sessions in PHP and session extension. 20 | 21 | ## [Databases](/php/ext/db) 22 | 23 | Access databases with PHP. 24 | 25 | ## [Regex](regex.md) 26 | 27 | Regular expressions in PHP. 28 | 29 | ## [Phar](phar.md) 30 | 31 | Phar (PHP Archive) 32 | -------------------------------------------------------------------------------- /php/ext/db/README.md: -------------------------------------------------------------------------------- 1 | # Databases 2 | 3 | * [What is a database and how to access databases from PHP?](intro.md) 4 | * [Database management systems vs. file systems?](database-vs-filesystem.md) 5 | * [PDO](pdo.md) 6 | -------------------------------------------------------------------------------- /php/ext/db/database-vs-filesystem.md: -------------------------------------------------------------------------------- 1 | # Database management systems vs. file systems? 2 | 3 | ## Database management systems vs. file systems 4 | 5 | * DBMS - A computerized record-keeping system 6 | * File System - A collection of individual files accessed by applications programs. 7 | 8 | ## Common limitations of some file system based DBs 9 | 10 | * Separated and Isolated Data - Makes coordinating, assimilating and representing data difficult 11 | * Data Duplication - Wastes space and can lead to data integrity (inconsistency) problems 12 | * Application Program Dependencies - Changes to a single file can require changes to numerous application programs 13 | * Incompatible Files 14 | 15 | ## Advantages of a DBMS 16 | 17 | * Data Consistency and Integrity - by controlling access and minimizing data duplication 18 | * Application program independence - by storing data in a uniform fashion 19 | * Data Sharing - by controlling access to data items, many users can access data concurrently 20 | * Checkpointing and Recovery 21 | * Security and Privacy 22 | * Multiple views of data 23 | * Expandability, Flexibility, Scalability 24 | * Reduced application development times once the system is in place 25 | * Standards enforcement 26 | * However ..... 27 | * Commercial DBMS often have high initial cost 28 | * Many DBMSs have high overhead - require powerful computers 29 | * DBMS are not special purpose software programs 30 | * Performance depends on the application 31 | 32 | ## When is a DBMS not necessarily appropriate? 33 | 34 | * Database is small with a simple structure 35 | * Applications are simple, special purpose and relatively static. 36 | * Concurrent, multi-user access to data is not required. 37 | * Need a quick prototype to demonstrate feasibility 38 | * Need an easy way to see the data without having to write a program 39 | * Customers don't want to install a DBMS and want to get online quickly 40 | -------------------------------------------------------------------------------- /php/ext/phar.md: -------------------------------------------------------------------------------- 1 | # How to create Phar (PHP Archive)? 2 | 3 | ## Packed php application archive 4 | 5 | ``` 6 | Note 7 | "This action needs the php.ini setting phar.readonly to be set to 0 in order to work for Phar objects. Otherwise, a PharException will be thrown." 8 | ``` 9 | 10 | PHAR (“Php ARchive”) is analogous to the JAR file concept but for PHP. If you have PHP 5.3 or greater, the Phar extension is built-in and enabled; you can start using it without any additional requirements. 11 | PHAR files are treated as read-only by default, and you can use any PHAR file without any special configuration. This is great for deployment. But as you'll be creating your own PHARs you'll need to allow write-access which is done through the php.ini file. 12 | Open `php.ini`, find the `phar.readonly` directive, and modify it accordingly: 13 | 14 | ```ini 15 | phar.readonly = 0 16 | ``` 17 | 18 | Now you're ready to package your libraries and applications as PHARs. 19 | 20 | Below simple code can create phar from folder `project` or change it to your project name. 21 | 22 | ```php 23 | buildFromDirectory(dirname(__FILE__) . '/project'); 28 | $phar->setStub($phar->createDefaultStub('cli/index.php', 'www/index.php')); 29 | 30 | $phar2 = new Phar('project2.phar', 0, 'project2.phar'); 31 | // add all files in the project, only include php files 32 | $phar2->buildFromDirectory(dirname(__FILE__) . '/project', '/\.php$/'); 33 | $phar2->setStub($phar->createDefaultStub('cli/index.php', 'www/index.php')); 34 | ``` 35 | -------------------------------------------------------------------------------- /php/ext/sessions/README.md: -------------------------------------------------------------------------------- 1 | # PHP sessions 2 | 3 | ## [Introduction](intro.md) 4 | 5 | Get to know what sessions are and how they work. 6 | -------------------------------------------------------------------------------- /php/ext/sessions/intro.md: -------------------------------------------------------------------------------- 1 | # Sessions 2 | 3 | Sessions in web applications provide a way to persist data between requests. 4 | 5 | When you start a new PHP session with `session_start()`, by default, there is a 6 | file created on the server somewhere in system temporary folder (/tmp on Linux, 7 | for example or the location set in the php.ini file under the `session.save_path` 8 | INI directive). File name can be of format `sess_ag525kn0fk6ik9r84kap9lkbfl` and 9 | its contents contain your `$_SESSION` data. 10 | 11 | And there is also a special single cookie created in user browser with name 12 | `PHPSESSID` and value of something like `ag525kn0fk6ik9r84kap9lkbfl` 13 | 14 | That cookie *connects* the user *browser* with that file where `$_SESSION` info 15 | is stored. Quite a simple storing mechanism. 16 | 17 | Now, these traditional sessions are slow and performance bottlenecks soon so other 18 | ways of storage are used, or also if you want to make them more secure, they can 19 | be encrypted (that file contents) and so on. 20 | 21 | Whatever you do, try not to store anything sensitive in cookies. You actually 22 | won't need to create and use custom created cookies at all in most cases. Only 23 | for example, when you want to display that EU cookie warnings and to remember is 24 | user clicked "ok, don't display this next time". And similar cases. 25 | 26 | For login, sessions are the way to go. 27 | 28 | Yes, `session_destroy()` removes that file on the server but the PHPSESSID cookie 29 | remains on the user browser. Which is not problematic because the new tmp file on 30 | the server will be created next time you call `session_start()` with new content 31 | of your defined $_SESSION array contents... 32 | -------------------------------------------------------------------------------- /php/intro/README.md: -------------------------------------------------------------------------------- 1 | # PHP introduction 2 | 3 | ## [Getting started](start.md) 4 | 5 | Learn what is PHP and why you should use it. 6 | 7 | ## [PHP installation](installation.md) 8 | 9 | To be able to follow these chapters, you need to install PHP and some 10 | prerequisites on your system. 11 | 12 | ## [Editors and IDEs](editors.md) 13 | 14 | For writing PHP code, you will need a text editor or IDE. This chapter will 15 | introduce you to some useful tools. 16 | 17 | ## [PHP basics](basics.md) 18 | 19 | Create PHP hello world and learn about the essential elements of PHP. 20 | -------------------------------------------------------------------------------- /php/intro/basics.md: -------------------------------------------------------------------------------- 1 | # PHP basics 2 | 3 | This chapter will go through a simple PHP program and show you basic PHP syntax. 4 | 5 | ## Hello world 6 | 7 | Let's create a *hello world* PHP program, and display the output in the 8 | command line and in browser. 9 | 10 | Create a new file called `hello.php` with the following contents: 11 | 12 | ```php 13 | 31 | 32 | ## PHP tags 33 | 34 | First line in above file is a so called *opening PHP tag* - ` 41 | 42 | 43 | 44 | 45 | ``` 46 | 47 | * Opening PHP tag: `` 49 | 50 | And display it in the browser: 51 | 52 | ```bash 53 | php -S localhost:8000 php-and-html.php 54 | ``` 55 | 56 | Now, visit URL `http://localhost:8000` in your favourite browser, and you should 57 | see output of `Hello world`. 58 | 59 | ## Comments 60 | 61 | Comments in code are language elements that indicate which parts of the code 62 | should not be parsed and processed. PHP provides two types of comments: 63 | 64 | * Single line comments: 65 | 66 | ```php 67 | 0 { 7 | return $x; 8 | } else { 9 | return -$x; 10 | } 11 | ``` 12 | 13 | ## Loops 14 | 15 | ```php 16 | // for 17 | for ($i = 1; $i<10; $i++) {} 18 | 19 | // while 20 | while ($i < 10) {} 21 | 22 | // do while 23 | $i = 0; 24 | do { 25 | echo $i; 26 | } while ($i > 0); 27 | 28 | 29 | // foreach 30 | foreach ($array as $key => $value) {} 31 | ``` 32 | 33 | ## Switch 34 | 35 | ```php 36 | // switch statement 37 | switch ($operatingSystem) { 38 | case 'darwin': 39 | echo 'Mac OS Hipster'; 40 | break; 41 | case 'linux': 42 | echo 'Linux Geek'; 43 | break; 44 | default: 45 | // Windows, BSD, ... 46 | echo 'Other'; 47 | } 48 | ``` 49 | -------------------------------------------------------------------------------- /php/ref/cookies.md: -------------------------------------------------------------------------------- 1 | # Cookies 2 | 3 | A cookie is a file that the server sets on user's computer to contain some information as key value pair. 4 | 5 | It is sent with every request to the server. 6 | 7 | The maximum size of a cookie must not exceed 4 Kilo Bytes. 8 | 9 | You can access the cookie variables through the `$_COOKIE` global variable. 10 | 11 | Warnings: 12 | - The user can disable cookies on his browser. 13 | - You must not use cookies to store sensitive information as it is not protected. 14 | 15 | ### Setting a cookie 16 | Using `setcookie` function. 17 | ```php 18 | setcookie( 19 | string $name, 20 | string $value = "", 21 | int $expires = 0, 22 | string $path = "", 23 | string $domain = "", 24 | bool $secure = false, 25 | bool $httponly = false 26 | ): bool 27 | 28 | // Alternative signature available as of PHP 7.3.0 29 | setcookie(string $name, string $value = "", array $options = []): bool 30 | 31 | ``` 32 | 33 | ### Cookie configuration 34 | 35 | - `$expires` sets the time the cookie should expire. 36 | - `$path` is the path on the server in which the cookie will be available on. Setting it to `/` makes it available to the entire domain. 37 | - `$domain` is the subdomain that the cookie is available to. 38 | - `$secure` if set to `true` make it available to `https` only. 39 | - `$httponly` if set to true make it accessible only through the HTTP protocol. This means that the cookie won't be accessible by JavaScript. 40 | 41 | 42 | ### Deleting the cookie 43 | 44 | You can do this by setting the `$expires` parameter to negative value. 45 | 46 | ```PHP 47 | setcookie($cookie_name, '' ,time() - 3600); 48 | ``` -------------------------------------------------------------------------------- /php/ref/errors.md: -------------------------------------------------------------------------------- 1 | # Errors 2 | 3 | When you develop you will definitely want to turn on error reporting in PHP. It 4 | gives you valuable information as to why something has failed. Let's check some 5 | of the most important error reporting directives in `php.ini`: 6 | 7 | * **error_reporting** 8 | 9 | This sets which errors should be reported. Using `E_ALL` is a good practice. 10 | 11 | * **display_errors** 12 | 13 | This handles displaying errors to the screen. 14 | 15 | * **log_errors** 16 | 17 | This controls reporting errors to a log file. Recommended practice is to 18 | always have this enabled. 19 | 20 | * **error_log** 21 | 22 | This defines error log file where errors should be written. It only applies 23 | if `log_errors` is enabled. 24 | 25 | Showing errors should depend on the environment your application is present. 26 | 27 | ```php 28 | getMessage(), "\n"; 19 | } finally { 20 | echo "This is always executed.\n"; 21 | } 22 | ``` 23 | -------------------------------------------------------------------------------- /php/ref/functions.md: -------------------------------------------------------------------------------- 1 | # Functions 2 | 3 | A function is a language element that wraps a block of code between curly bracket 4 | characters and provides reusable functionality throughout your program. 5 | 6 | Let's take a look at a simple example: 7 | 8 | ```php 9 | An anti-pattern is a common response to a recurring problem that is usually 4 | > ineffective and risks being highly counterproductive. The term, coined in 5 | > 1995 by Andrew Koenig, was inspired by a book, "Design Patterns", which 6 | > highlights a number of design patterns in software development that its 7 | > authors considered to be highly reliable and effective. 8 | 9 | * [Wikipedia](https://en.wikipedia.org/wiki/Anti-pattern) 10 | 11 | ## See also 12 | 13 | * [AntiPatterns eBook](https://sourcemaking.com/antipatterns) 14 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/README.md: -------------------------------------------------------------------------------- 1 | # Design patterns in PHP 2 | 3 | * [What are design patterns in PHP?](intro.md) 4 | * [Abstract factory](abstract-factory.md) 5 | * [Adapter](adapter.md) 6 | * [Bridge](bridge.md) 7 | * [Builder](builder.md) 8 | * [Chain of responsibility](chain-of-responsibility.md) 9 | * [Command](command.md) 10 | * [Composite](composite.md) 11 | * [Decorator](decorator.md) 12 | * [Dependency injection](dependency-injection.md) 13 | * [Facade](facade.md) 14 | * [Flyweight](flyweight.md) 15 | * [Interpreter](interpreter.md) 16 | * [Iterator](iterator.md) 17 | * [Lazy loading](lazy-loading.md) 18 | * [Mediator](mediator.md) 19 | * [Memento](memento.md) 20 | * [Mock object](mock-object.md) 21 | * [Null object](null-object.md) 22 | * [Object pool](object-pool.md) 23 | * [Observer](observer.md) 24 | * [Prototype](prototype.md) 25 | * [Proxy design pattern](proxy.md) 26 | * [Servant design pattern](servant.md) 27 | * [Singleton design pattern](singleton.md) 28 | * [State design pattern](state.md) 29 | * [Strategy design pattern](strategy.md) 30 | * [Template method](template-method.md) 31 | * [Type tunnel design pattern](type-tunnel.md) 32 | * [Visitor design pattern](visitor.md) 33 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/abstract-factory.md: -------------------------------------------------------------------------------- 1 | # Abstract factory design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Abstract factory design pattern](https://en.wikipedia.org/wiki/Abstract_factory_pattern) 6 | * [DesignPatternsPHP: Abstract Factory](http://designpatternsphp.readthedocs.io/en/latest/Creational/AbstractFactory/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/adapter.md: -------------------------------------------------------------------------------- 1 | # Adapter design pattern in PHP 2 | 3 |  4 | 5 | ## See also 6 | 7 | * [Wikipedia: Adapter pattern](http://en.wikipedia.org/wiki/Adapter_pattern) 8 | * [DesignPatternsPHP: Adapter/Wrapper](http://designpatternsphp.readthedocs.io/en/latest/Structural/Adapter/README.html) 9 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/bridge.md: -------------------------------------------------------------------------------- 1 | # Bridge design pattern with PHP example 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Bridge pattern](https://en.wikipedia.org/wiki/Bridge_pattern) 6 | * [DesignPatternsPHP: Bridge pattern](http://designpatternsphp.readthedocs.io/en/latest/Structural/Bridge/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/builder.md: -------------------------------------------------------------------------------- 1 | # Builder design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Builder pattern](https://en.wikipedia.org/wiki/Builder_pattern) 6 | * [DesignPatternsPHP: Builder pattern](http://designpatternsphp.readthedocs.io/en/latest/Creational/Builder/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/chain-of-responsibility.md: -------------------------------------------------------------------------------- 1 | # Chain of responsibility design pattern with PHP example 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Chain-of-responsibility pattern](https://en.wikipedia.org/wiki/Chain-of-responsibility_pattern) 6 | * [DesignPatternsPHP: Chain Of Responsibilities](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/ChainOfResponsibilities/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/command.md: -------------------------------------------------------------------------------- 1 | # Command design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Command pattern](https://en.wikipedia.org/wiki/Command_pattern) 6 | * [DesignPatternsPHP: Command](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/Command/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/composite.md: -------------------------------------------------------------------------------- 1 | # Composite design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Composite pattern](https://en.wikipedia.org/wiki/Composite_pattern) 6 | * [DesignPatternsPHP: Composite](http://designpatternsphp.readthedocs.io/en/latest/Structural/Composite/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/decorator.md: -------------------------------------------------------------------------------- 1 | # Decorator design pattern with PHP example 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Decorator pattern](https://en.wikipedia.org/wiki/Decorator_pattern) 6 | * [DesignPatternsPHP: Decorator](http://designpatternsphp.readthedocs.io/en/latest/Structural/Decorator/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/facade.md: -------------------------------------------------------------------------------- 1 | # Facade design pattern with PHP example 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Facade pattern](https://en.wikipedia.org/wiki/Facade_pattern) 6 | * [DesignPatternsPHP: Facade](http://designpatternsphp.readthedocs.io/en/latest/Structural/Facade/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/flyweight.md: -------------------------------------------------------------------------------- 1 | # Flyweight design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Flyweight pattern](https://en.wikipedia.org/wiki/Flyweight_pattern) 6 | * [DesignPatternsPHP: Flyweight](http://designpatternsphp.readthedocs.io/en/latest/Structural/Flyweight/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/interpreter.md: -------------------------------------------------------------------------------- 1 | # Interpreter design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Interpreter pattern](https://en.wikipedia.org/wiki/Interpreter_pattern) 6 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/iterator.md: -------------------------------------------------------------------------------- 1 | # Iterator design pattern in PHP 2 | 3 | Iterator design pattern is a software design pattern which provides access to 4 | the elements of an aggregate object sequentially without exposing its 5 | underlying representation. It makes elements appear as a collection of objects. 6 | 7 | * Promote to "full object status" the traversal of a collection. 8 | * Polymorphic traversal 9 | 10 | ## PHP implementations 11 | 12 | * PHP offers [Iterator interface](http://php.net/manual/en/class.iterator.php) 13 | out of the box. Its SPL library has also a wide variety of 14 | [useful iterators](http://php.net/manual/en/spl.iterators.php). After 15 | understanding the basics of the iterator pattern using these instead of 16 | reinventing the wheel is more convenient. 17 | 18 | ## See also 19 | 20 | * [Wikipedia: Iterator pattern](https://en.wikipedia.org/wiki/Iterator_pattern) 21 | * [DesignPatternsPHP: Iterator](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/Iterator/README.html) 22 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/mediator.md: -------------------------------------------------------------------------------- 1 | # Mediator design pattern with PHP example 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Mediator pattern](https://en.wikipedia.org/wiki/Mediator_pattern) 6 | * [DesignPatternsPHP: Mediator](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/Mediator/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/memento.md: -------------------------------------------------------------------------------- 1 | # Memento design pattern in PHP 2 | 3 | ## UML diagram 4 | 5 |  6 | 7 | ## See also 8 | 9 | * [Memento design pattern on Wikipedia](http://en.wikipedia.org/wiki/Memento_pattern) 10 | * [DesignPatternsPHP: Memento](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/Memento/README.html) 11 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/mock-object.md: -------------------------------------------------------------------------------- 1 | # Mock object design pattern in PHP 2 | 3 | Mock objects imitate the behavior of the real objects. They are used in 4 | testing, where creating mock objects makes testing simpler and still provides 5 | the same behavior as the real object used in the application code. They can 6 | also be used as a base while developing a specific part of an application in a 7 | team, without utilizing the entire application. 8 | 9 | ## Implementations 10 | 11 | * [PHPUnit](https://phpunit.de/manual/current/en/test-doubles.html) 12 | 13 | ## See also 14 | 15 | * [Wikipedia: Mock object](https://en.wikipedia.org/wiki/Mock_object) 16 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/observer.md: -------------------------------------------------------------------------------- 1 | # Observer design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Observer pattern](https://en.wikipedia.org/wiki/Observer_pattern) 6 | * [DesignPatternsPHP: Observer pattern](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/Observer/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/prototype.md: -------------------------------------------------------------------------------- 1 | # Prototype design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Prototype pattern](https://en.wikipedia.org/wiki/The_Observer) 6 | * [DesignPatternsPHP: Prototype](http://designpatternsphp.readthedocs.io/en/latest/Creational/Prototype/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/proxy.md: -------------------------------------------------------------------------------- 1 | # Proxy design pattern in PHP 2 | 3 |  4 | 5 | ## See also 6 | 7 | * [Wikipedia: Proxy pattern](https://en.wikipedia.org/wiki/Proxy_pattern) 8 | * [DesignPatternsPHP: Proxy](http://designpatternsphp.readthedocs.io/en/latest/Structural/Proxy/README.html) 9 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/servant.md: -------------------------------------------------------------------------------- 1 | # Servant design pattern in PHP 2 | 3 | Servant design pattern is a behavioral design pattern where multiple classes 4 | use the servant's class behavior to **avoid repeating code** 5 | (*see: [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself)*). 6 | Behavior functionality is defined only in one place: In servant. 7 | 8 | The servant design pattern is not a defined pattern in the Gang of Four (GoF) 9 | book. It is very similar to the 10 | [command design pattern](/php/ref/oop/design-patterns/command.md) 11 | but with a somewhat different solution to the problem. 12 | 13 |  14 | 15 | ## See also 16 | 17 | * [Wikipedia: Servant design pattern](https://en.wikipedia.org/wiki/Servant_(design_pattern)) 18 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/state.md: -------------------------------------------------------------------------------- 1 | # State design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: State pattern](https://en.wikipedia.org/wiki/State_pattern) 6 | * [DesignPatternsPHP: State](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/State/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/strategy.md: -------------------------------------------------------------------------------- 1 | # Strategy design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Strategy pattern](https://en.wikipedia.org/wiki/Strategy_pattern) 6 | * [DesignPatternsPHP: Strategy](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/Strategy/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/template-method.md: -------------------------------------------------------------------------------- 1 | # Template method design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Template method pattern](https://en.wikipedia.org/wiki/Template_method_pattern) 6 | * [DesignPatternsPHP: Template method](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/TemplateMethod/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/type-tunnel.md: -------------------------------------------------------------------------------- 1 | # Type tunnel design pattern in PHP 2 | 3 | The type tunnel pattern is not exactly a recognized software design pattern by 4 | GoF (Gang of Four book). Type tunnel is used in cases where multiple unrelated 5 | types are passed (tunneled) through adaptation layer and converted to the type 6 | the underlying layer expects. 7 | 8 |  9 | 10 | Type tunnel also has side effects that compensate its benefits, because in a 11 | dynamically typed language such as PHP, the types can be solved differently. 12 | 13 | It can be used best in statically typed programming languages such as C++, but 14 | in case of PHP, implementing type tunnel isn't really applicable. 15 | 16 | ## See also 17 | 18 | * [Type Tunnel](https://en.wikipedia.org/wiki/Type_Tunnel_pattern) 19 | * [Generalized String Manipulation: Access Shims and Type Tunneling](http://www.drdobbs.com/generalized-string-manipulation-access-s/184401689) 20 | * [PHP Types](http://php.net/manual/en/language.types.php) 21 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/visitor.md: -------------------------------------------------------------------------------- 1 | # Visitor design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Visitor pattern](https://en.wikipedia.org/wiki/Visitor_pattern) 6 | * [DesignPatternsPHP: Visitor pattern](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/Visitor/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/dic.md: -------------------------------------------------------------------------------- 1 | # What is dependency injection container in PHP? 2 | 3 | To better understand dependency injection container, the 4 | [dependency injection design pattern](/php/ref/oop/design-patterns/dependency-injection.md) 5 | is a prerequisite. 6 | 7 | Dependency injection container is very useful and recommended way of managing 8 | class dependencies. It is a utility which helps you to implement the dependency 9 | injection pattern in your application. 10 | 11 | Dependency injection container is a combination of container design pattern, 12 | factory pattern and (optionally) flyweight pattern when utilizing objects as 13 | service descriptors. General implementations of dependency injection container 14 | are also inspecting components (utilizing reflection). 15 | 16 | ## See also 17 | 18 | * [PHP-DI](http://php-di.org/) - Dependency injection container PHP library. 19 | * [Pimple](http://pimple.sensiolabs.org/) - A simple PHP dependency injection 20 | container. 21 | * [Do you need a Dependency Injection Container?](http://fabien.potencier.org/do-you-need-a-dependency-injection-container.html) 22 | * [Symfony Dependency Injection Component](http://symfony.com/doc/current/components/dependency_injection.html) 23 | * [Laravel Service Container](https://laravel.com/docs/5.3/container) 24 | * [Aura.DI](https://github.com/auraphp/Aura.Di) 25 | * [Dependency Injection: An analogy](https://mwop.net/blog/260-Dependency-Injection-An-analogy.html) 26 | -------------------------------------------------------------------------------- /php/ref/oop/solid.md: -------------------------------------------------------------------------------- 1 | # SOLID 2 | 3 | SOLID is a collection of good programming practices for object oriented 4 | programming and consists of 6 principles. These aren't rules that you should be 5 | following strictly everywhere. These are more like best practices you should 6 | use when possible and understood. If there are better practices than these 7 | found and developed at some point in the future, they too will be extended and 8 | explained in separate chapters. 9 | 10 | SOLID stands for: 11 | 12 | * **S** as single responsibility principle 13 | * **O** as open/close principle 14 | * **L** as Liskov segregation principle 15 | * **I** as interface segregation principle 16 | * **D** as dependency inversion principle 17 | 18 | ## Single Responsibility Principle (SRP) 19 | 20 | Single responsibility principle states that each class or module should have 21 | one and only one role or responsibility. 22 | 23 | ## Open/Close Principle (OC) 24 | 25 | Open/close principle states that each class should be open for extension and at 26 | the same time closed for modification. 27 | 28 | ## Liskov Segregation Principle (LSP) 29 | 30 | Liskov segregation principle states that objects should be replaceable with 31 | instances of any of their parent classes. 32 | 33 | ## Interface Segregation Principle (ISP) 34 | 35 | Interface segregation principle states that classes should not be limited and 36 | locked for accepting more of their kind. 37 | 38 | ## Dependency Inversion Principle 39 | 40 | Dependency inversion principle states that classes should depend on 41 | abstractions rather than only certain class dependencies. Abstraction should be 42 | implemented without detailed functionality so that classes can use the 43 | abstraction and extend it accordingly. 44 | 45 | ## See also 46 | 47 | The following resources are advised to read beside this article to get 48 | different explanations and to know more about the SOLID principles. 49 | 50 | * [Wikipedia: SOLID (object oriented design)](https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)) 51 | -------------------------------------------------------------------------------- /php/ref/operators.md: -------------------------------------------------------------------------------- 1 | # Operators 2 | 3 | ## Arithmetic operators 4 | 5 | |Operator|Name|Result| 6 | |--------|----|-----------| 7 | |`-$a`|negation|Opposite of $a.| 8 | |`$a + $b`|addition|Sum of $a and $b.| 9 | |`$a - $b`|Subtraction|Difference of $a and $b.| 10 | |`$a * $b`|Multiplication|Product of $a and $b.| 11 | |`$a / $b`|division|Quotient of $a and $b.| 12 | |`$a % $b`|modulus|Remainder of $a divided by $b.| 13 | |`$a ** $b`|Exponentiation|Result of raising $a to the $b'th power.| 14 | 15 | ## Comparison operators 16 | 17 | |Operator|Name|Result| 18 | |--------|----|-----------| 19 | |`$a == $b`|Equal|TRUE if $a is equal to $b after type juggling.| 20 | |`$a === $b`|Identical|TRUE if $a is equal to $b, and they are of the same type.| 21 | |`$a != $b`|Not equal|TRUE if $a is not equal to $b after type juggling.| 22 | |`$a <> $b`|Not equal|TRUE if $a is not equal to $b after type juggling.| 23 | |`$a !== $b`|Not identical|TRUE if $a is not equal to $b, or they are not of the same type.| 24 | |`$a < $b`|Less than|TRUE if $a is strictly less than $b.| 25 | |`$a > $b`|Greater than|TRUE if $a is strictly greater than $b.| 26 | |`$a <= $b`|Less than or equal to|TRUE if $a is less than or equal to $b.| 27 | |`$a >= $b`|Greater than or equal to|TRUE if $a is greater than or equal to $b.| 28 | |`$a <=> $b`|Spaceship|-1 if $a is less than $b, 1 if $a is greater than $b, otherwise 0.| 29 | 30 | ## Logical operators 31 | 32 | |Operator|Name|Result| 33 | |--------|----|------| 34 | |`! $a`|Not|TRUE if $a is not TRUE.| 35 | |`$a && $b`|And|TRUE if both $a and $b are TRUE.| 36 | |`$a || $b`|Or|TRUE if either $a or $b is TRUE.| 37 | |`$a and $b`|And|Like `&&` but precedence is lower.| 38 | |`$a or $b`|Or|Like `||` but precedence is lower.| 39 | |`$a xor $b`|Xor|TRUE if either $a or $b is TRUE, but not both.| 40 | 41 | ## Simple-assignment operators 42 | 43 | The simple-assignment operator `=` assigns its right operand to its left operand. 44 | 45 | ```php 46 | >=`|`$x >>= $y`|`$x = $x >> $y`| 66 | |`&=`|`$x &= $y`|`$x = $x & $y`| 67 | |`^=`|`$x ^= $y`|`$x = $x ^ $y`| 68 | |`|=`|`$x |= $y`|`$x = $x | $y`| 69 | -------------------------------------------------------------------------------- /php/ref/predefined-variables.md: -------------------------------------------------------------------------------- 1 | # Predefined variables 2 | 3 | PHP provides multiple predefined variables. 4 | 5 | ## Superglobals 6 | 7 | ## $_GLOBALS 8 | 9 | ## $_SERVER 10 | 11 | ## $_GET 12 | 13 | ## $_POST 14 | 15 | ## $_FILES 16 | 17 | ## $_REQUEST 18 | 19 | ## $_SESSION 20 | 21 | ## $_ENV 22 | 23 | ## $_COOKIE 24 | 25 | ## $php\_errormsg 26 | 27 | ## $HTTP\_RAW\_POST\_DATA 28 | 29 | ## $http\_response\_header 30 | 31 | ## $argc 32 | 33 | ## $argv 34 | -------------------------------------------------------------------------------- /php/ref/references.md: -------------------------------------------------------------------------------- 1 | # References 2 | -------------------------------------------------------------------------------- /php/ref/sessions.md: -------------------------------------------------------------------------------- 1 | # Sessions 2 | 3 | A session is a way to store information to be used across multiple pages. 4 | 5 | Unlike a cookie, the information is not stored on the users computer. It is stored either on a file on the server, in the database (MySQL for example), or Redis. 6 | 7 | You can access the session variables through the `$_SESSION` global variable. 8 | 9 | ### Starting the session 10 | 11 | You can start the session using the `session_start()` function. If it has already started nothing will happen. 12 | 13 | Note : The `session_start()` function must be the first thing to be called in the file. 14 | 15 | ### Session configuration 16 | 17 | There are many configuration settings for sessions, and you can check them out in the [manual](https://www.php.net/manual/en/session.configuration.php), but we'll focus on just the most important ones here. 18 | 19 | - `session.name` allows you to change the default session name to the name you want. 20 | 21 | - `session.auto_start` starts the session automatically. The default is `false`. 22 | 23 | - `session.gc_maxlifetime` sets the maximum lifetime for the session before invalidating it. 24 | 25 | ### Session cookie name 26 | 27 | You can know the session name by calling the `session_name()` function. The default name is `PHPSESSID`, but you can change it easily in 4 ways: 28 | 29 | - In your `php.ini` file via the `session.name` setting. 30 | 31 | - Through Apache. 32 | 33 | - Via your `.htaccess` file. 34 | 35 | - By using the `ini_set()` function at the start of the file before calling the `session_start()` function. 36 | 37 | ### Invalidating the session 38 | 39 | You can achieve this in 3 ways: 40 | 41 | - By calling the `session_unset()` function which unsets the `$_SESSION` variable. 42 | 43 | - By expiring the session cookie in the user's browser: 44 | ```PHP 45 | setcookie(session_name(), '' ,time() - 3600); 46 | ``` 47 | 48 | - By calling the `session_destroy()` function. 49 | -------------------------------------------------------------------------------- /php/ref/types/README.md: -------------------------------------------------------------------------------- 1 | # PHP types 2 | 3 | PHP supports 10 primitive types: 4 | 5 | ## Scalar types 6 | 7 | * boolean 8 | * integer 9 | * float (float pointing number or double) 10 | * string 11 | 12 | ## Compound types 13 | 14 | * [array](arrays.md) 15 | * object 16 | * callable 17 | * iterable 18 | 19 | ## Special types 20 | 21 | * resource 22 | * NULL 23 | -------------------------------------------------------------------------------- /php/ref/types/arrays.md: -------------------------------------------------------------------------------- 1 | # Arrays 2 | 3 | Array is a container with a fixed number of elements, where each element is 4 | indexed from `0` incrementally: 5 | 6 | ```php 7 | 'bar', 22 | 'bar' => 'foo', 23 | ]; 24 | 25 | // Outputs "bar" 26 | echo $array['foo']; 27 | ``` 28 | 29 | ## Operations on arrays 30 | 31 | | Operator | Name | Result | 32 | |----------|------|--------| 33 | | `$a + $b` | Union|Union of $a and $b. | 34 | | `$a == $b` | Equality | TRUE if $a and $b have the same key/value pairs. | 35 | | `$a === $b` | Identity | TRUE if $a and $b have the same key/value pairs in the same order and of the same types. | 36 | | `$a != $b` | Inequality |TRUE if $a is not equal to $b. | 37 | | `$a <> $b` | Inequality | TRUE if $a is not equal to $b. | 38 | | `$a !== $b` | Non-identity | TRUE if $a is not identical to $b. | 39 | -------------------------------------------------------------------------------- /php/ref/variables.md: -------------------------------------------------------------------------------- 1 | # Variables 2 | 3 | Variable is used to store some value in your program. PHP variables are prefixed 4 | with a dollar sign `$`. 5 | 6 | ```php 7 | 'foo', 2 => 'bar']); 8 | var_dump($json); 9 | // string(21) "{"0":"foo","2":"bar"}" 10 | 11 | // An array with ordered indexes will be array by default 12 | $json = json_encode([0 => 'foo', 1 => 'bar']); 13 | var_dump($json); 14 | // string(13) "["foo","bar"]" 15 | 16 | // JSON_FORCE_OBJECT will make it an object 17 | $json = json_encode([0 => 'foo', 1 => 'bar'], JSON_FORCE_OBJECT); 18 | var_dump($json); 19 | // string(21) "{"0":"foo","1":"bar"}" 20 | ``` 21 | -------------------------------------------------------------------------------- /tips/arrays/README.md: -------------------------------------------------------------------------------- 1 | # Array tips 2 | 3 | * [JSON_FORCE_OBJECT](01-json-force-object.md) 4 | -------------------------------------------------------------------------------- /tips/composer/01-performance.md: -------------------------------------------------------------------------------- 1 | # Better performance with Composer 2 | 3 | Composer is de-facto standard package manager for PHP. To get better performance 4 | when installing PHP packages, use the lightning fast 5 | [prestissimo plugin](https://github.com/hirak/prestissimo). 6 | 7 | Install the plugin globally: 8 | 9 | ```bash 10 | composer require hirak/prestissimo 11 | ``` 12 | 13 | And as usual, use Composer to get a performance boost of ~10x because of 14 | parallel installations: 15 | 16 | ```bash 17 | composer install 18 | ``` 19 | -------------------------------------------------------------------------------- /tips/composer/README.md: -------------------------------------------------------------------------------- 1 | # Composer tips 2 | 3 | * [Performance](01-performance.md) 4 | -------------------------------------------------------------------------------- /tips/datetime/01-copyright-year.md: -------------------------------------------------------------------------------- 1 | # Year in the Footer 2 | 3 | Many websites include current year and copyright info in the footer. A neat way 4 | to stay current is to output the year dynamically. 5 | 6 | Instead of this: 7 | 8 | ```php 9 | echo '2016 © Acme'; 10 | ``` 11 | 12 | You can output the current year dynamically: 13 | 14 | ```php 15 | echo date('Y').' © Acme'; 16 | ``` 17 | -------------------------------------------------------------------------------- /tips/datetime/02-datetime.md: -------------------------------------------------------------------------------- 1 | # DateTime::createFromFormat 2 | 3 | Pipe and exclamation mark characters reset all fields (year, month, day, hour, 4 | minute, second, fraction, and timezone information) to the Unix Epoch. 5 | 6 | http://php.net/manual/en/datetime.createfromformat.php 7 | 8 | ```php 9 | $date = '2015-10-21'; 10 | 11 | $date_1 = DateTime::createFromFormat('Y-m-d', $date); 12 | 13 | // Y-m-d| will set the year, month and day to the information found 14 | // in the string to parse, and sets the hour, minute and second to 0. 15 | $date_2 = DateTime::createFromFormat('Y-m-d|', $date); 16 | 17 | var_dump($date_1->format('r'), $date_2->format('r')); 18 | // string(31) "Wed, 21 Oct 2015 04:32:09 +0200" 19 | // string(31) "Wed, 21 Oct 2015 00:00:00 +0200" 20 | ``` 21 | -------------------------------------------------------------------------------- /tips/datetime/03-easter.md: -------------------------------------------------------------------------------- 1 | # How to get the date of Easter in PHP? 2 | 3 | If PHP is compiled with `--enable-calendar`, you can use `easter_date()`: 4 | http://php.net/manual/en/function.easter-date.php 5 | 6 | ```php 7 | if (time() <= easter_date(2017)) { 8 | echo 'HaPHPy Easter!'; 9 | } 10 | ``` 11 | 12 | and `easter_days()`: 13 | http://php.net/manual/en/function.easter-days.php 14 | 15 | The computation of the date of Easter can also be done [manually](https://en.wikipedia.org/wiki/Computus). 16 | -------------------------------------------------------------------------------- /tips/datetime/README.md: -------------------------------------------------------------------------------- 1 | # Date and time tips 2 | 3 | * [Copyright year](01-copyright-year.md) 4 | * [DateTime](02-datetime.md) 5 | * [How to get the date of Easter in PHP?](03-easter.md) 6 | -------------------------------------------------------------------------------- /tips/oop/01-visibility.md: -------------------------------------------------------------------------------- 1 | # Visibility 2 | 3 | Private and protected properties of classes are not about security, but provide 4 | information about the code for users, to let them know how to use them. 5 | 6 | http://php.net/manual/en/language.oop5.visibility.php 7 | 8 | Private and protected properties can be read by converting objects to arrays, 9 | closures, or by reverse-engineering using the reflection API. 10 | 11 | ```php 12 | class Foo 13 | { 14 | private $private = "private"; 15 | protected $protected = "protected"; 16 | } 17 | ``` 18 | 19 | Retrieving the private property value directly results in a fatal error: 20 | 21 | ```php 22 | $foo = new Foo(); 23 | var_dump($foo->private); 24 | // PHP Fatal error: Uncaught Error: Cannot access private property Foo::$private in 7.php: 17 25 | ``` 26 | 27 | Converting to an array: 28 | 29 | ```php 30 | $foo = (array) $foo; 31 | var_dump($foo["\0Foo\0private"]); 32 | var_dump($foo["\0*\0protected"]); 33 | // string(7) "private" 34 | // string(7) "protected" 35 | ``` 36 | 37 | Using the reflection API: 38 | 39 | ```php 40 | $foo = new Foo(); 41 | $reflection = new ReflectionObject($foo); 42 | $private = $reflection->getProperty('private'); 43 | $private->setAccessible(true); 44 | var_dump($private->getValue($foo)); 45 | // string(7) "private" 46 | 47 | $protected = $reflection->getProperty('protected'); 48 | $protected->setAccessible(true); 49 | var_dump($protected->getValue($foo)); 50 | // string(7) "protected" 51 | ``` 52 | 53 | Using a closure: 54 | 55 | ```php 56 | $foo = new Foo(); 57 | var_dump((function(){return $this->private;})->bindTo($foo, $foo)()); 58 | var_dump((function(){return $this->protected;})->bindTo($foo, $foo)()); 59 | // string(7) "private" 60 | // string(7) "protected" 61 | ``` 62 | -------------------------------------------------------------------------------- /tips/oop/README.md: -------------------------------------------------------------------------------- 1 | # OOP tips 2 | 3 | * [Visibility](01-visibility.md) 4 | -------------------------------------------------------------------------------- /tips/strings/01-emails.md: -------------------------------------------------------------------------------- 1 | # Validating emails 2 | 3 | You can use PHP filters to validate emails with PHP - `FILTER_VALIDATE_EMAIL`. 4 | 5 | ```php 6 | $email = $_POST['email'] ?? null; 7 | 8 | if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { 9 | $error = 'Invalid email'; 10 | } 11 | ``` 12 | -------------------------------------------------------------------------------- /tips/strings/README.md: -------------------------------------------------------------------------------- 1 | # Strings tips 2 | 3 | * [Validating emails](01-emails.md) 4 | -------------------------------------------------------------------------------- /tips/style/01-ifs.md: -------------------------------------------------------------------------------- 1 | # Return from if statements as soon as possible 2 | 3 | ```php 4 | function foo($bar, $baz) { 5 | if (!checkSomething($bar, $baz)) { 6 | if (!findSomething($bar, $baz)) { 7 | if (!checkFoo($bar, $baz)) { 8 | if (count($bar) > 0 && $baz == 1) { 9 | doSomething(); 10 | } 11 | } 12 | } 13 | } 14 | } 15 | ``` 16 | 17 | Instead, this is much more readable and manageable: 18 | 19 | ```php 20 | function foo($bar, $baz) { 21 | if (checkSomething($bar)) { 22 | return; 23 | } 24 | 25 | if (findSomething($bar, $baz)) { 26 | return; 27 | } 28 | 29 | if (checkFoo($bar, $baz)) { 30 | return; 31 | } 32 | 33 | if (!(count($bar) > 0 && $baz == 1)) { 34 | return; 35 | } 36 | 37 | doSomething(); 38 | } 39 | ``` 40 | -------------------------------------------------------------------------------- /tips/style/README.md: -------------------------------------------------------------------------------- 1 | # Style tips 2 | 3 | * [Return from if statements as soon as possible](01-ifs.md) 4 | -------------------------------------------------------------------------------- /tips/unicorns/01-comments.md: -------------------------------------------------------------------------------- 1 | # Comments 2 | 3 | When you want to comment out a chunk of code, you can do so by just removing a 4 | single backslash. 5 | 6 | ```php 7 | //* 8 | $debug = true; 9 | die(var_dump($debug)); 10 | //*/ 11 | ``` 12 | 13 | ```php 14 | /* 15 | $debug = true; 16 | die(var_dump($debug)); 17 | //*/ 18 | ``` 19 | -------------------------------------------------------------------------------- /tips/unicorns/02-dir.md: -------------------------------------------------------------------------------- 1 | # Including files 2 | 3 | When dealing with file includes, `__DIR__` can be a significant help. 4 | 5 | ```php 6 | include __DIR__.'/../relative/path/to/file.php'; 7 | ``` 8 | -------------------------------------------------------------------------------- /tips/unicorns/03-haystack-needle.md: -------------------------------------------------------------------------------- 1 | # Haystack/Needle 2 | 3 | All string functions are haystack/needle, and array functions are needle/haystack, 4 | except for `array_filter()`. 5 | -------------------------------------------------------------------------------- /tips/unicorns/04-ternary-operator.md: -------------------------------------------------------------------------------- 1 | # Ternary Operator 2 | 3 | Most times the same action can be done with the ternary operator. The following 4 | lines of code show same conditional usages. 5 | 6 | ```php 7 | if ($i === 2) { 8 | $j = 0; 9 | } else { 10 | ++$j; 11 | } 12 | ``` 13 | 14 | With ternary operator you can do a one-liner: 15 | 16 | ```php 17 | $j = ($i === 2) ? 0 : ++$j; 18 | ``` 19 | -------------------------------------------------------------------------------- /tips/unicorns/README.md: -------------------------------------------------------------------------------- 1 | # Other PHP tips 2 | 3 | * [Comments](01-comments.md) 4 | * [Including files](02-dir.md) 5 | * [Haystack/Needle](03-haystack-needle.md) 6 | * [Ternary operator](04-ternary-operator.md) 7 | --------------------------------------------------------------------------------