PHP disable_functions

Updated: 26 November 2024

See https://www.php.net/manual/en/ini.core.php#ini.disable-functions


PHP INI file setting

disable_functions='get_magic_quotes_gpc'

PHP check script

error_reporting(E_ALL);
get_magic_quotes_gpc();
var_dump(function_exists('get_magic_quotes_gpc'));

Output with PHP 7.4. Note the deprecation warning is still displayed

Deprecated: Function get_magic_quotes_gpc() is deprecated in ...
Warning: get_magic_quotes_gpc() has been disabled for security reasons in ...
bool(false)

Laravel Homestead

Updated: 06 May 2024

IP address of host from inside of Homestead: 10.0.2.2


Connect via ssh, from the Homestead directory

vagrant ssh

Run composer with php version 7.2

php7.2 /usr/local/bin/composer update

Reset to original state

vagrant destroy --force && vagrant up

Reload

vagrant reload --provision

Check which PHP versions have xdebug enabled

phpquery -v 5.6 -s fpm -m xdebug
phpquery -v 7.0 -s fpm -m xdebug
phpquery -v 7.1 -s fpm -m xdebug
phpquery -v 7.2 -s fpm -m xdebug
phpquery -v 7.3 -s fpm -m xdebug
phpquery -v 7.4 -s fpm -m xdebug
phpquery -v 8.0 -s fpm -m xdebug
phpquery -v 8.1 -s fpm -m xdebug
phpquery -v 8.2 -s fpm -m xdebug
phpquery -v 8.3 -s fpm -m xdebug

Enable the Xdebug module for the fpm SAPI of PHP version 5.6

phpenmod -v 5.6 -s fpm -m xdebug

PHP PECL & PEAR

Updated: 26 November 2024

PECL
https://pecl.php.net

The PHP Extension Community Library

PECL is a repository for PHP Extensions, providing a directory of all known extensions and hosting facilities for downloading and development of PHP extensions.

PEAR
https://pear.php.net

PHP Extension & Application Repository

PEAR is a framework and distribution system for reusable PHP components.

PHP code examples

Updated: 12 March 2024

Read contents of text file into a variable

$file_pointer = fopen('raw_bb_sample.txt', 'r') or die('Unable to open file!');
$sample = fread($file_pointer, filesize('raw_bb_sample.txt'));
fclose($file_pointer);
var_dump($sample);

Symfony testing

Updated: 10 December 2024

See https://symfony.com/doc/current/testing.html

Unit Tests

  1. Test a Class.
  2. Test a method in a Class.
  3. Equivalent to standard PHPUnit unit tests.
  4. Does not hit the database – use mocks instead.

Integration Tests

  1. Tests a larger part of the app than Unit tests e.g. a combination of Services.
  2. Might use the Kernel to fetch services from the dependency injection container.
  3. Integration test classes should extend KernelTestCase.
  4. May involve mocking of Class dependencies.
  5. May interact with a test database, populated via fixtures.

Application Tests

  1. Checks integration of all layers of the app, from routing to views, excluding on page javascript.
  2. Has a specific workflow:
    1. Make request.
    2. Interact with page.
    3. Test response.
  3. Probably won’t involve mocking dependencies.
  4. Probably will interact with a test database.
  5. Integration test classes should extend WebTestCase.

End to End Tests

  1. Test the application as a whole, including on page JavaScript code.
  2. Involves a real browser instead of the test client.
  3. See Symfony Panther component.

The output of make:test supplies a useful summary

root@5b8333e33939:/var/www/html# bin/console make:test

 Which test type would you like?:
  [TestCase       ] basic PHPUnit tests
  [KernelTestCase ] basic tests that have access to Symfony services
  [WebTestCase    ] to run browser-like scenarios, but that do not execute JavaScript code
  [ApiTestCase    ] to run API-oriented scenarios
  [PantherTestCase] to run e2e scenarios, using a real-browser or HTTP client and a real web server