UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

91 lines (74 loc) 2.6 kB
--- layout: page title: "JavaScript ini_set function" comments: true sharing: true footer: true alias: - /functions/view/ini_set:600 - /functions/view/ini_set - /functions/view/600 - /functions/ini_set:600 - /functions/600 --- <!-- Generated by Rakefile:build --> A JavaScript equivalent of PHP's ini_set {% codeblock info/ini_set.js lang:js https://raw.github.com/kvz/phpjs/master/functions/info/ini_set.js raw on github %} function ini_set (varname, newvalue) { // From: http://phpjs.org/functions // + original by: Brett Zamir (http://brett-zamir.me) // % note 1: This will not set a global_value or access level for the ini item // * test: skip // * example 1: ini_set('date.timezone', 'America/Chicago'); // * returns 1: 'Asia/Hong_Kong' var oldval = ''; var self = this; try { this.php_js = this.php_js || {}; } catch (e) { this.php_js = {}; } this.php_js.ini = this.php_js.ini || {}; this.php_js.ini[varname] = this.php_js.ini[varname] || {}; oldval = this.php_js.ini[varname].local_value; var _setArr = function (oldval) { // Although these are set individually, they are all accumulated if (typeof oldval === 'undefined') { self.php_js.ini[varname].local_value = []; } self.php_js.ini[varname].local_value.push(newvalue); }; switch (varname) { case 'extension': if (typeof this.dl === 'function') { // This function is only experimental in php.js this.dl(newvalue); } _setArr(oldval, newvalue); break; default: this.php_js.ini[varname].local_value = newvalue; break; } return oldval; } {% endcodeblock %} - [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/info/ini_set.js) Please note that php.js uses JavaScript objects as substitutes for PHP arrays, they are the closest match to this hashtable-like data structure. Please also note that php.js offers community built functions and goes by the [McDonald's Theory](https://medium.com/what-i-learned-building/9216e1c9da7d). We'll put online functions that are far from perfect, in the hopes to spark better contributions. Do you have one? Then please just: - [Edit on GitHub](https://github.com/kvz/phpjs/edit/master/functions/info/ini_set.js) ### Example 1 This code {% codeblock lang:js example %} ini_set('date.timezone', 'America/Chicago'); {% endcodeblock %} Should return {% codeblock lang:js returns %} 'Asia/Hong_Kong' {% endcodeblock %} ### Other PHP functions in the info extension {% render_partial _includes/custom/info.html %}