Skip to content

Instantly share code, notes, and snippets.

View rotexdegba's full-sized avatar

Rotimi Ade rotexdegba

View GitHub Profile
@rotexdegba
rotexdegba / new-in-php-7-X.md
Created June 18, 2019 17:02
A list of changes in PHP 7.0+ all on one page

New Stuff in PHP 7.0

  1. Scalar type definitions: they come in two flavours: coercive (default) and strict. The following types for parameters can now be enforced (either coercively or strictly): strings (string), integers (int), floating-point numbers (float), and booleans (bool). They augment the other types introduced in PHP 5: class names, interfaces, array and callable.
    • https://blog.programster.org/php-strict-types
    • Typed pass-by-reference Parameters gotcha: Declared types of reference parameters are checked on function entry, but not when the function returns, so after the function had returned, the argument's type may have changed. For example:
    <?php
    function array_baz(array &$param)
    {

$param = 1;

@rotexdegba
rotexdegba / xdebug-netbeans.md
Last active August 17, 2022 23:08
Debugging PHP with Xdebug in Netbeans 8.2
  • Make sure xdebug is enabled in your php installation
  • The following lines worked for me in my php.ini with PHP 7.2 on Windows 10
[xdebug]
zend_extension ="php_xdebug-2.6.1-7.2-vc15-x86_64.dll"
;xdebug.remote_enable=1
;xdebug.remote_handler=dbgp
;xdebug.remote_mode=req
;xdebug.remote_host=127.0.0.1
;xdebug.remote_port=9000
@rotexdegba
rotexdegba / object-has-get-property.php
Created June 28, 2018 17:31
Object Property Detection and Object Property Value Retrieval
<?php
/**
*
* A robust way of retrieving the value of a a specified property in
* an instance of a class.
*
* Works with \stdClass objects created from arrays with numeric key(s)
* (the value of the propertie(s) with numeric key(s) in such \stdClass
* objects will be retrieved by this function).
*
@rotexdegba
rotexdegba / old-collection.php
Created May 13, 2018 06:59
Old Collection Class
<?php
/**
*
* A collection of Cfs_Model_Base_Record records.
* @package Cfs_Model
*
*/
class Cfs_Model_Base_Collection extends Solar_Sql_Model_Collection {
/**
@rotexdegba
rotexdegba / named-js-functions.js
Last active December 12, 2017 20:55
How to execute a JavaScript function when I have its name as a string
// see also https://stackoverflow.com/questions/359788/how-to-execute-a-javascript-function-when-i-have-its-name-as-a-string
window.example = function () { alert('hello world'); };
//or
name = 'example';
window[name] = function () { alert('hello world'); };
//or
window[name] = new Function( 'alert("hello world")' );
@rotexdegba
rotexdegba / phpword-view-template-for-promis2.0.php
Created July 5, 2017 22:23
phpword-view-template-for-promis2.0
<?php
$phpword_writer_wrapper = new \Promis2\PhpWordWriterWrapper();
// New Word document
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Do stuff with $phpWord
// ............
// ............
@rotexdegba
rotexdegba / format-bytes.php
Created October 13, 2016 04:35
Format Bytes to Readable Unit
<?php
function formatSizeUnits($bytes)
{
if ($bytes >= 1073741824)
{
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
}
elseif ($bytes >= 1048576)
{
$bytes = number_format($bytes / 1048576, 2) . ' MB';

See https://cheatsheetseries.owasp.org/, it's more comprehensive and up to date

PHP Security checklist

Basic

  • Strong passwords are used.
  • Passwords stored safely.
  • register_globals is disabled.
@rotexdegba
rotexdegba / linux-rails-and-redmin-in-ubuntu-1604-mint18.txt
Last active December 3, 2023 15:49
Installing Rails and Redmine in Ubuntu 16.04 LTS / Linux Mint 18
# Make sure you have already installed apache and mysql;
# install rails
# https://help.ubuntu.com/lts/serverguide/ruby-on-rails.html
sudo apt install rails
# install comman dependencies
sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev make libmysqlclient-dev imagemagick \
libmagickcore-dev libmagickwand-dev