Esempio n. 1
0
$tests[] = array('title' => 'ICONV extension', 'required' => TRUE, 'passed' => extension_loaded('iconv') && ICONV_IMPL !== 'unknown' && @iconv('UTF-16', 'UTF-8//IGNORE', iconv('UTF-8', 'UTF-16//IGNORE', 'test')) === 'test', 'message' => 'Enabled and works properly', 'errorMessage' => 'Disabled or does not work properly', 'description' => 'ICONV extension is required and must work properly.');
$tests[] = array('title' => 'JSON extension', 'required' => TRUE, 'passed' => extension_loaded('json'));
$tests[] = array('title' => 'Fileinfo extension', 'required' => FALSE, 'passed' => extension_loaded('fileinfo'), 'description' => 'Fileinfo extension is absent. You will not be able to detect content-type of uploaded files.');
$tests[] = array('title' => 'PHP tokenizer', 'required' => TRUE, 'passed' => extension_loaded('tokenizer'), 'description' => 'PHP tokenizer is required.');
$tests[] = array('title' => 'PDO extension', 'required' => FALSE, 'passed' => $pdo = extension_loaded('pdo') && PDO::getAvailableDrivers(), 'message' => $pdo ? 'Available drivers: ' . implode(' ', PDO::getAvailableDrivers()) : NULL, 'description' => 'PDO extension or PDO drivers are absent. You will not be able to use <code>Nette\\Database</code>.');
$tests[] = array('title' => 'Multibyte String extension', 'required' => FALSE, 'passed' => extension_loaded('mbstring'), 'description' => 'Multibyte String extension is absent. Some internationalization components may not work properly.');
$tests[] = array('title' => 'Multibyte String function overloading', 'required' => TRUE, 'passed' => !extension_loaded('mbstring') || !(mb_get_info('func_overload') & 2), 'message' => 'Disabled', 'errorMessage' => 'Enabled', 'description' => 'Multibyte String function overloading is enabled. Nette Framework requires this to be disabled. If it is enabled, some string function may not work properly.');
$tests[] = array('title' => 'Memcache extension', 'required' => FALSE, 'passed' => extension_loaded('memcache'), 'description' => 'Memcache extension is absent. You will not be able to use <code>Nette\\Caching\\Storages\\MemcachedStorage</code>.');
$tests[] = array('title' => 'GD extension', 'required' => FALSE, 'passed' => extension_loaded('gd'), 'description' => 'GD extension is absent. You will not be able to use <code>Nette\\Image</code>.');
$tests[] = array('title' => 'Bundled GD extension', 'required' => FALSE, 'passed' => extension_loaded('gd') && GD_BUNDLED, 'description' => 'Bundled GD extension is absent. You will not be able to use some functions such as <code>Nette\\Image::filter()</code> or <code>Nette\\Image::rotate()</code>.');
$tests[] = array('title' => 'Fileinfo extension or mime_content_type()', 'required' => FALSE, 'passed' => extension_loaded('fileinfo') || function_exists('mime_content_type'), 'description' => 'Fileinfo extension or function <code>mime_content_type()</code> are absent. You will not be able to determine mime type of uploaded files.');
$tests[] = array('title' => 'HTTP_HOST or SERVER_NAME', 'required' => TRUE, 'passed' => isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME']), 'message' => 'Present', 'errorMessage' => 'Absent', 'description' => 'Either <code>$_SERVER["HTTP_HOST"]</code> or <code>$_SERVER["SERVER_NAME"]</code> must be available for resolving host name.');
$tests[] = array('title' => 'REQUEST_URI or ORIG_PATH_INFO', 'required' => TRUE, 'passed' => isset($_SERVER['REQUEST_URI']) || isset($_SERVER['ORIG_PATH_INFO']), 'message' => 'Present', 'errorMessage' => 'Absent', 'description' => 'Either <code>$_SERVER["REQUEST_URI"]</code> or <code>$_SERVER["ORIG_PATH_INFO"]</code> must be available for resolving request URL.');
$tests[] = array('title' => 'SCRIPT_NAME or DOCUMENT_ROOT & SCRIPT_FILENAME', 'required' => TRUE, 'passed' => isset($_SERVER['SCRIPT_NAME']) || isset($_SERVER['DOCUMENT_ROOT'], $_SERVER['SCRIPT_FILENAME']), 'message' => 'Present', 'errorMessage' => 'Absent', 'description' => '<code>$_SERVER["SCRIPT_NAME"]</code> or <code>$_SERVER["DOCUMENT_ROOT"]</code> with <code>$_SERVER["SCRIPT_FILENAME"]</code> must be available for resolving script file path.');
$tests[] = array('title' => 'REMOTE_ADDR or php_uname("n")', 'required' => TRUE, 'passed' => isset($_SERVER['REMOTE_ADDR']) || function_exists('php_uname'), 'message' => 'Present', 'errorMessage' => 'Absent', 'description' => '<code>$_SERVER["REMOTE_ADDR"]</code> or <code>php_uname("n")</code> must be available for detecting development / production mode.');
paint($tests);
/**
 * Paints checker.
 * @param  array
 * @return void
 */
function paint($requirements)
{
    $redirect = round(time(), -1);
    if (!isset($_GET) || isset($_GET['r']) && $_GET['r'] == $redirect) {
        $redirect = NULL;
    }
    $errors = $warnings = FALSE;
    foreach ($requirements as $id => $requirement) {
        $requirements[$id] = $requirement = (object) $requirement;
        if (isset($requirement->passed) && !$requirement->passed) {
<html>
<head>
	<meta charset="UTF-8">
	<title>Default Argument Values</title>
</head>
<body>

	<?php 
// If you dont have a value for color use red or office for room
function paint($room = "office", $color = "red")
{
    return "The color of the {room} is {$color}.<br />";
}
echo paint();
// custom
echo paint("bedroom", "blue");
// The special NULL value represents a variable with no value. NULL is the only possible value of type null.
echo paint("bedroom", null);
echo paint("blue");
// order still matters
?>
	
</body>
</html>
Esempio n. 3
0
<!-- ======================
=
======================= -->

<h2>Default Function Values</h2>

<?php 
function paint($room = "office", $color = "red")
{
    return "The color of the {$room} is {$color}.<br />";
}
echo paint();
echo paint("bedroom", "blue");
echo paint("bedroom", null);
echo paint("lounge");
?>

<!-- ======================
=
======================= -->

<!-- <h2>Form Processing</h2>

  <form action="form_processing.php" method="post">
    Username: <input type="text" name="username" value="" /><br />
    Password: <input type="password" name="password" value=""><br />
    <br />
    <input type="submit" name="submit" value="Submit" />
  </form> -->
Esempio n. 4
0
 * @copyright  Copyright (c) 2004, 2009 David Grudl
 */
/**
 * Check PHP configuration.
 */
foreach (array('function_exists', 'version_compare', 'extension_loaded', 'ini_get') as $function) {
    if (!function_exists($function)) {
        die("Error: function '{$function}' is required by Nette Framework and this Requirements Checker.");
    }
}
/**
 * Check Nette Framework requirements.
 */
define('CHECKER_VERSION', '1.2');
$reflection = class_exists('ReflectionFunction') && !iniFlag('zend.ze1_compatibility_mode') ? new ReflectionFunction('paint') : NULL;
paint(array(array('title' => 'Web server', 'message' => $_SERVER['SERVER_SOFTWARE']), array('title' => 'PHP version', 'required' => TRUE, 'passed' => version_compare(PHP_VERSION, '5.2.0', '>='), 'message' => PHP_VERSION, 'description' => 'Your PHP version is too old. Nette Framework requires at least PHP 5.2.0 or higher.'), array('title' => 'Memory limit', 'message' => ini_get('memory_limit')), 'ha' => array('title' => '.htaccess file protection', 'required' => FALSE, 'description' => 'File protection by <code>.htaccess</code> is optional. If it is absent, you must be careful to put files into document_root folder.', 'script' => "var el = document.getElementById('resha');\nel.className = typeof checkerScript == 'undefined' ? 'passed' : 'warning';\nel.parentNode.removeChild(el.nextSibling.nodeType === 1 ? el.nextSibling : el.nextSibling.nextSibling);"), array('title' => 'Function ini_set', 'required' => FALSE, 'passed' => function_exists('ini_set'), 'description' => 'Function <code>ini_set()</code> is disabled. Some parts of Nette Framework may not work properly.'), array('title' => 'Magic quotes', 'required' => FALSE, 'passed' => !iniFlag('magic_quotes_gpc') && !iniFlag('magic_quotes_runtime'), 'message' => 'Disabled', 'errorMessage' => 'Enabled', 'description' => 'Magic quotes <code>magic_quotes_gpc</code> and <code>magic_quotes_runtime</code> are enabled and should be turned off. Nette Framework disables <code>magic_quotes_runtime</code> automatically.'), array('title' => 'Register_globals', 'required' => TRUE, 'passed' => !iniFlag('register_globals'), 'message' => 'Disabled', 'errorMessage' => 'Enabled', 'description' => 'Configuration directive <code>register_globals</code> is enabled. Nette Framework requires this to be disabled.'), array('title' => 'Zend.ze1_compatibility_mode', 'required' => TRUE, 'passed' => !iniFlag('zend.ze1_compatibility_mode'), 'message' => 'Disabled', 'errorMessage' => 'Enabled', 'description' => 'Configuration directive <code>zend.ze1_compatibility_mode</code> is enabled. Nette Framework requires this to be disabled.'), array('title' => 'Variables_order', 'required' => TRUE, 'passed' => strpos(ini_get('variables_order'), 'G') !== FALSE && strpos(ini_get('variables_order'), 'P') !== FALSE && strpos(ini_get('variables_order'), 'C') !== FALSE, 'description' => 'Configuration directive <code>variables_order</code> is missing. Nette Framework requires this to be set.'), array('title' => 'Reflection extension', 'required' => TRUE, 'passed' => (bool) $reflection, 'description' => 'Reflection extension is required.'), array('title' => 'Reflection phpDoc', 'required' => FALSE, 'passed' => $reflection ? strpos($reflection->getDocComment(), 'Paints') !== FALSE : FALSE, 'description' => 'Reflection phpDoc are not available (probably due to an eAccelerator bug). Persistent parameters must be declared using static function.'), array('title' => 'SPL extension', 'required' => TRUE, 'passed' => extension_loaded('SPL'), 'description' => 'SPL extension is required.'), array('title' => 'PCRE extension', 'required' => TRUE, 'passed' => extension_loaded('pcre'), 'description' => 'PCRE extension is required.'), array('title' => 'ICONV extension', 'required' => TRUE, 'passed' => extension_loaded('iconv') && ICONV_IMPL !== 'unknown' && @iconv('UTF-16', 'UTF-8//IGNORE', iconv('UTF-8', 'UTF-16//IGNORE', 'test')) === 'test', 'message' => 'Enabled and works properly', 'errorMessage' => 'Disabled or works not properly', 'description' => 'ICONV extension is required and must work properly.'), array('title' => 'Multibyte String extension', 'required' => FALSE, 'passed' => extension_loaded('mbstring'), 'description' => 'Multibyte String extension is absent. Some internationalization components may not work properly.'), array('title' => 'Multibyte String function overloading', 'required' => TRUE, 'passed' => !extension_loaded('mbstring') || !(mb_get_info('func_overload') & 2), 'message' => 'Disabled', 'errorMessage' => 'Enabled', 'description' => 'Multibyte String function overloading is enabled. Nette Framework requires this to be disabled. If it is enabled, some string function may not work properly.'), array('title' => 'Memcache extension', 'required' => FALSE, 'passed' => extension_loaded('memcache'), 'description' => 'Memcache extension is absent. You will not be able to use <code>Nette\\Caching\\MemcachedStorage</code>.'), array('title' => 'GD extension', 'required' => FALSE, 'passed' => extension_loaded('gd'), 'description' => 'GD extension is absent. You will not be able to use <code>Nette\\Image</code>.'), array('title' => 'Bundled GD extension', 'required' => FALSE, 'passed' => extension_loaded('gd') && GD_BUNDLED, 'description' => 'Bundled GD extension is absent. You will not be able to use some function as <code>Nette\\Image::filter()</code> or <code>Nette\\Image::rotate()</code>.'), array('title' => 'ImageMagick library', 'required' => FALSE, 'passed' => @exec('identify -format "%w,%h,%m" ' . addcslashes(dirname(__FILE__) . '/assets/logo.gif', ' ')) === '176,104,GIF', 'description' => 'ImageMagick server library is absent. You will not be able to use <code>Nette\\ImageMagick</code>.'), array('title' => 'Fileinfo extension or mime_content_type()', 'required' => FALSE, 'passed' => extension_loaded('fileinfo') || function_exists('mime_content_type'), 'description' => 'Fileinfo extension or function <code>mime_content_type()</code> are absent. You will not be able to determine mime type of uploaded files.'), array('title' => 'HTTP extension', 'required' => FALSE, 'passed' => !extension_loaded('http'), 'message' => 'Disabled', 'errorMessage' => 'Enabled', 'description' => 'HTTP extension has naming conflict with Nette Framework. You have to disable this extension or use „prefixed“ version.'), array('title' => 'HTTP_HOST or SERVER_NAME', 'required' => TRUE, 'passed' => isset($_SERVER["HTTP_HOST"]) || isset($_SERVER["SERVER_NAME"]), 'message' => 'Present', 'errorMessage' => 'Absent', 'description' => 'Either <code>$_SERVER["HTTP_HOST"]</code> or <code>$_SERVER["SERVER_NAME"]</code> must be available for resolving host name.'), array('title' => 'REQUEST_URI or ORIG_PATH_INFO', 'required' => TRUE, 'passed' => isset($_SERVER["REQUEST_URI"]) || isset($_SERVER["ORIG_PATH_INFO"]), 'message' => 'Present', 'errorMessage' => 'Absent', 'description' => 'Either <code>$_SERVER["REQUEST_URI"]</code> or <code>$_SERVER["ORIG_PATH_INFO"]</code> must be available for resolving request URL.'), array('title' => 'SCRIPT_FILENAME, SCRIPT_NAME, PHP_SELF', 'required' => TRUE, 'passed' => isset($_SERVER["SCRIPT_FILENAME"], $_SERVER["SCRIPT_NAME"], $_SERVER["PHP_SELF"]), 'message' => 'Present', 'errorMessage' => 'Absent', 'description' => '<code>$_SERVER["SCRIPT_FILENAME"]</code> and <code>$_SERVER["SCRIPT_NAME"]</code> and <code>$_SERVER["PHP_SELF"]</code> must be available for resolving script file path.'), array('title' => 'SERVER_ADDR or LOCAL_ADDR', 'required' => TRUE, 'passed' => isset($_SERVER["SERVER_ADDR"]) || isset($_SERVER["LOCAL_ADDR"]), 'message' => 'Present', 'errorMessage' => 'Absent', 'description' => '<code>$_SERVER["SERVER_ADDR"]</code> or <code>$_SERVER["LOCAL_ADDR"]</code> must be available for detecting development / production mode.')));
/**
 * Paints checker.
 * @param  array
 * @return void
 */
function paint($requirements)
{
    $redirect = round(time(), -1);
    if (!isset($_GET) || isset($_GET['r']) && $_GET['r'] == $redirect) {
        $redirect = NULL;
    }
    $errors = $warnings = FALSE;
    foreach ($requirements as $id => $requirement) {
        $requirements[$id] = $requirement = (object) $requirement;
        if (isset($requirement->passed) && !$requirement->passed) {
    $bar = "inside";
}
foo();
echo $bar . "<br>";
?>
            <br>
        <!-- using global variable -->
        <?php 
$bar = "outside";
function foo2()
{
    //declare that the variable is global
    global $bar;
    $bar = "inside";
}
foo2();
echo $bar . "<br>";
?>
        <br>
        <?php 
function paint($color = "blue")
{
    // blue if the default value if no color is passedin
    echo "Paint my room {$color}";
}
paint();
?>

    </body>
</html>
<div class="container">
  <div class="page-header">
<h2>Functions: Setting Default Argument Values</h2>
</div>

<?php 
function paint($room = "office", $color = "red")
{
    return "The color of the {$room} is {$color}.<br>";
}
echo paint();
echo paint("bedroom", "blue");
echo paint("bedroom");
echo paint("blue");
echo paint();
?>

</div>











Esempio n. 7
0
/**
 * Check PHP configuration.
 */
foreach (array('function_exists', 'version_compare', 'extension_loaded', 'ini_get') as $function) {
    if (!function_exists($function)) {
        die("Error: function '{$function}' is required by Nette Framework and this Requirements Checker.");
    }
}
/**
 * Check Nette Framework requirements.
 */
define('CHECKER_VERSION', '1.1');
define('REQUIRED', TRUE);
define('OPTIONAL', FALSE);
$reflection = class_exists('ReflectionFunction') && !iniFlag('zend.ze1_compatibility_mode') ? new ReflectionFunction('paint') : NULL;
paint(array(array('PHP version', REQUIRED, version_compare(PHP_VERSION, '5.2.0', '>='), 'PHP version 5.2.0 or higher is required by Nette Framework.'), array('Function ini_set', OPTIONAL, function_exists('ini_set'), 'Function ini_set() is optional. If it is absent, some parts of framework may not work properly.'), array('Reflection extension', REQUIRED, (bool) $reflection, 'Reflection extension is required.'), array('Reflection phpDoc', OPTIONAL, $reflection ? strpos($reflection->getDocComment(), 'Paints') !== FALSE : FALSE, 'Reflection phpDoc is optional. If it is absent, persistent parameters must be declared using static function.'), array('SPL extension', REQUIRED, extension_loaded('SPL'), 'SPL extension is required.'), array('PCRE extension', REQUIRED, extension_loaded('pcre'), 'PCRE extension is required.'), array('ICONV extension', REQUIRED, extension_loaded('iconv') && ICONV_IMPL !== 'unknown' && @iconv('UTF-16', 'UTF-8//IGNORE', iconv('UTF-8', 'UTF-16//IGNORE', 'test')) === 'test', 'ICONV extension is required and must work properly.'), array('$_SERVER["HTTP_HOST"] or "SERVER_NAME"', REQUIRED, isset($_SERVER["HTTP_HOST"]) || isset($_SERVER["SERVER_NAME"]), 'Either $_SERVER["HTTP_HOST"] or $_SERVER["SERVER_NAME"] must be available for resolving host name.'), array('$_SERVER["REQUEST_URI"] or "ORIG_PATH_INFO"', REQUIRED, isset($_SERVER["REQUEST_URI"]) || isset($_SERVER["ORIG_PATH_INFO"]), 'Either $_SERVER["REQUEST_URI"] or $_SERVER["ORIG_PATH_INFO"] must be available for resolving request URL.'), array('$_SERVER["SCRIPT_FILENAME"] and "SCRIPT_NAME" and "PHP_SELF"', REQUIRED, isset($_SERVER["SCRIPT_FILENAME"], $_SERVER["SCRIPT_NAME"], $_SERVER["PHP_SELF"]), '$_SERVER["SCRIPT_FILENAME"] and $_SERVER["SCRIPT_NAME"] and $_SERVER["PHP_SELF"] must be available for resolving script file path.'), array('$_SERVER["SERVER_ADDR"] or "LOCAL_ADDR"', REQUIRED, isset($_SERVER["SERVER_ADDR"]) || isset($_SERVER["LOCAL_ADDR"]), '$_SERVER["SERVER_ADDR"] or $_SERVER["LOCAL_ADDR"] must be available for detecting development/production mode.'), 'ha' => array('.htaccess file protection', OPTIONAL, NULL, 'File protection by .htaccess is optional. If it is absent, you must be careful to put files into document_root folder.', '<script>var el = document.getElementById("resha").getElementsByTagName("td").item(0); el.className = el.innerHTML = typeof checkerScript == "undefined" ? "passed" : "warning";</script>'), array('Multibyte String extension', OPTIONAL, extension_loaded('mbstring'), 'Multibyte String extension is optional. If it is absent, some internationalization components may not work properly.'), array('Multibyte String function overloading off', REQUIRED, !extension_loaded('mbstring') || !(mb_get_info('func_overload') & 2), 'Multibyte String function overloading must be turned off. If it is enabled, some string function may not work properly.'), array('Magic quotes off', OPTIONAL, !iniFlag('magic_quotes_gpc') && !iniFlag('magic_quotes_runtime'), 'Magic quotes "magic_quotes_gpc" & "magic_quotes_runtime" should be turned off. Framework disables magic_quotes_runtime automatically.'), array('Register_globals off', OPTIONAL, !iniFlag('register_globals'), 'Register_globals should be turned off.'), array('Zend.ze1_compatibility_mode off', REQUIRED, !iniFlag('zend.ze1_compatibility_mode'), 'zend.ze1_compatibility_mode must be turned off.'), array('Variables_order', REQUIRED, strpos(ini_get('variables_order'), 'G') !== FALSE && strpos(ini_get('variables_order'), 'P') !== FALSE && strpos(ini_get('variables_order'), 'C') !== FALSE, 'Variables_order is required.'), array('Memcache extension', OPTIONAL, extension_loaded('memcache'), 'Memcache extension is optional. If it is absent, you will not be able to use Nette\\Caching\\MemcachedStorage.'), array('GD extension', OPTIONAL, extension_loaded('gd'), 'GD extension is optional. If it is absent, you will not be able to use Nette\\Image.'), array('Bundled GD extension', OPTIONAL, extension_loaded('gd') && GD_BUNDLED, 'Bundled GD extension is optional. If it is absent, you will not be able to use some function as Nette\\Image::filter() or Nette\\Image::rotate().'), array('ImageMagick library', OPTIONAL, @exec('identify -format "%w,%h,%m" ' . addcslashes(dirname(__FILE__) . '/assets/checker.gif', ' ')) === '176,104,GIF', 'ImageMagick server library is optional. If it is absent, you will not be able to use Nette\\ImageMagick.'), array('Fileinfo extension or function mime_content_type', OPTIONAL, extension_loaded('fileinfo') || function_exists('mime_content_type'), 'Fileinfo extension or function mime_content_type are optional. If they are absent, you will not be able to determine mime type of uploaded files.'), array('Disabled HTTP extension', OPTIONAL, !extension_loaded('http'), 'HTTP extension has naming conflict with Nette Framework. If it is present, you will have to use Prefixed version.')));
/**
 * Paints checker.
 * @param  array
 * @return void
 */
function paint($requirements)
{
    $redirect = round(time(), -1);
    if (!isset($_GET) || isset($_GET['r']) && $_GET['r'] == $redirect) {
        $redirect = NULL;
    }
    $errors = array(REQUIRED => 0, OPTIONAL => 0);
    foreach ($requirements as $requirement) {
        list(, $required, $result) = $requirement;
        if (isset($result) && !$result) {
Esempio n. 8
0
		<?php 
$bar = "outside";
function foo()
{
    global $bar;
    $bar = "inside";
}
foo();
echo $bar . "<br />";
?>
		<br />
		<?php 
$bar = "outside";
function foo2($bar)
{
    $bar = "inside";
    return $bar;
}
$bar = foo2($bar);
echo $bar . "<br />";
?>
		<br />
		<?php 
function paint($room = "office", $colour = "red")
{
    echo "The colour of the {$room} is {$colour}.";
}
paint("bedroom", "blue");
?>
	</body>
</html>
Esempio n. 9
0
    }
    $bar = "inside";
    // Local scope
}
echo "1: " . $bar . "<br />";
foo();
echo "2: " . $bar . "<br />";
// Setting default arguments
function paint($room = "office", $color = "red")
{
    return "The color of the " . $room . " is " . $color . ".<br />";
}
echo paint();
echo paint("bedroom", "blue");
echo paint("bedroom", null);
echo paint(null, "blue");
/************************************************************
 * DEBUGGING
 ************************************************************/
// http://php.net/manual/en/errorfunc.constants.php
// http://xdebug.org
// http://www.php-debugger.com/dbg/
// http://www.firephp.org
// In PHP code you should turn ON error reporting
// ini_set('display_errors', 'On');
// error_reporting(E_ALL);
// error_reporting(E_ALL | E_STRICT);
// error_reporting();
// Fatal Error // Syntax Error // Warnings // Notices //
// Useful
// print_r($variable);	- print readable array
</pre>
</div>
</div>
<br><br>
<table width="500" border="0" align="center" cellpadding="1" cellspacing="1" class="tbl_border">
  <tr>
    <td><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="tbl_gray_wborder">
        <tr>
          <td class="txt14b_black">
            <p align="center"><span class="txt16b_blue">Sample Output: </span><br>
              <br>
<?php 
function paint($color = "red")
{
    echo "The color of the room is {$color}.";
}
paint();
paint(blue);
?>
<br>
              <br>
          </p></td>
        </tr>
    </table></td>
  </tr>
</table>

</body>
</html>
Esempio n. 11
0
}
$addiction = function ($first, $second) {
    return $first + $second;
};
$substraction = function ($first, $second) {
    return $first - $second;
};
echo math($addiction, 4, 3) . "\n";
function addSubt($value1, $value2)
{
    $add = $value1 + $value2;
    $subt = $value1 - $value2;
    return array($add, $subt);
}
$resultArray = addSubt(10, 4);
echo "Add: " . $resultArray[0] . "\n";
echo "Substr: " . $resultArray[1] . "\n";
list($addResult, $sustrResult) = addSubt(20, 5);
echo "Add: " . $addResult . "\n";
echo "Substr: " . $sustrResult . "\n";
function paint($pet = "doggie", $color = "red")
{
    return "The color for your {$pet} is {$color}. \n";
    // var_dump(debug_backtrace());
}
paint();
echo paint("kitty");
echo paint("tiger", "yellow");
// print_r( get_defined_vars() );
?>
					
<!DOCTYPE html">
<html lang="en">
<head>
    <title>Function: Default Arguments Values</title>
</head>
<body>
    <?php 
function paint($room = "office", $color = "red")
{
    return "The color of the {$room} is {$color}. <br/>";
}
echo paint();
echo paint("bedroom", "blue");
echo paint("bedroom", null);
echo paint("bedroom");
?>
</body>
</html>