[PHP] PHP Warning: Module ‘mcrypt’ already loaded in Unknown on line 0

Like in the title, PHP Warning: Module ‘mcrypt’ already loaded in Unknown on line 0.
When we launch whatever a command PHP, for example php -v, we will see the warning :

# php -v
PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/mcrypt.ini on line 1 in Unknown on line 0
PHP Warning:  Module 'mcrypt' already loaded in Unknown on line 0
...

This warning was caused by the duplicated configuration of the mcrypt extension.

To check it, we can use this command (the path could be changed depends on the local configuration):

grep "extension=mcrypt.so" /etc/php5/cli/php.ini

and

grep "extension=mcrypt.so" /etc/php5/cli/conf.d/mcrypt.ini

If the two command return the same thing : “extension=mcrypt.so”, this means the extension is included two times.

The solution is simple, juste remove one of these configuration, that will be ok.

[PHP] PHP Fatal error can’t use method return value in write context

Context :
Development with PHP

Error message :
PHP Fatal error can’t use method return value in write context

Code generated error :

if(empty(preg_match($pattern, $subject))){
  ....
}

Error reason (from php.net) :

Note:
Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.

Code corrected :

preg_match($pattern, $subject, $match);
if(empty( $match )){
  ....
}

[PHPUnit] Testing output

Test contains not only unit test, integration test, but also the output of screen, including files etc.

For example, with the function exceptOutputString, we can test the string output by echo or print.

<?php
class OutputTest extends PHPUnit_Framework_TestCase
{
    public function testExpectFooActualFoo()
    {
        $this->outputString();    // Call my local function
        $this->expectOutputString('Hello world!');    // Comparaison
    }

    // local function 
    private function outputString()
    {
        echo "Hello world!";
    }
}
?>

Ref. Methods for output testing

[French Vocabulary] maquette

maquette

n. f
1模型; 雏型; 设计模型; 原型
2草图, 画稿; (封面、插图、广告画等的)彩色原图
3(印刷物或版面的)设计, 设计方案

常见用法
faire des maquettes d’avions做飞机模型

ref. frdic