php,anonymous-functionRelated issues-Collection of common programming errors
Matt Ball
php computer-algebra-systems
I’m creating a CAS (Computer Algebra System) in PHP, but I’m stuck right now. I am using this website.Now I wrote a tokenizer. It will convert an equation like this:1+2x-3*(4-5*(3x))to this:NUMBER PLUS_OPERATOR NUMBER VAR[X] MINUS_OPERATOR NUMBER MULTIPLY_OPERATOR GROUP(where group is another set of tokens). How can I simplify this equation? Yeah, I know what you can do: adding X-vars, but they are in the sub-group. What is the best method I can use for handling those tokens?
iainjames88
php ubuntu-12.04 error-reporting internal-server-error
I’ve set up a fresh install of Ubuntu Server 12.04 LTS on Amazon AWS with *Apache2/MySQL/PHP5. When I run a PHP script and it encounters an error I don’t see any error reporting from PHP, all I see isHTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfil the request.I have checked my /etc/php5/apache2/php.ini file and as far as I can tell error reporting should be set up. The contents of the file (regarding errors) are:; displ
Charles
php oop
Using PHP 5.3 I’m experiencing weird / non-intuitive behavior when applying empty() to dynamic object properties fetched via the __get() overload function. Consider the following code snippet:<?phpclass Test {protected $_data= array(‘id’=> 23,’name’=> ‘my string’);function __get($k) {return $this->_data[$k];}}$test= new Test(); var_dump(“Accessing directly:”); var_dump($test->name); var_dump($test->id); var_dump(empty($test->name)); var_dump(empty($test->id));var_dump(“Ac
codaddict
php operators ternary-operator
This is what I wrote :$Myprovince = ( ($province == 6) ? “city-1” : ($province == 7) ? “city-2” : ($province == 8) ? “city-3” : ($province == 30) ? “city-4” : “out of borders” );But for every field I got the value city-4. I want to use ternary operators instead of switch/if because I want to experiment and see how it would be done.What’s the problem with this code?
Jess Telford
php unit-testing phpunit
When running a PHPUnit test, I would like to be able to dump output so I can debug one or two things.I have tried the following (similar to the PHPUnit Manual example);class theTest extends PHPUnit_Framework_TestCase {/*** @outputBuffering disabled*/public function testOutput() {print_r(“Hello World”);print “Ping”;echo “Pong”;$out = “Foo”;var_dump($out);} }With the following result:PHPUnit @package_version@ by Sebastian Bergmann..Time: 0 seconds, Memory: 3.00MbOK (1 test, 0 assertions)Notice
user456885
php multibyte
Given certain multibyte character sets, am I correct in assuming that the following doesn’t do what it was intended to do?$string = str_replace(‘”‘, ‘\\”‘, $string);In particular, if the input was in a character set that might have a valid character like 0xbf5c, so an attacker can inject 0xbf22 to get 0xbf5c22, leaving a valid character followed by an unquoted double quote (“).Is there an easy way to mitigate this problem, or am I misunderstanding the issue in the first place?(In my case, the st
testwork
php facebook facebook-graph-api facebook-php-sdk
I have a problem with posting image in more than one facebook pages. I am creating an image using GD Library.I am using facebook api to post in the pages with pageid and page access token. When a submit button is clicked for the first time the image is not uploaded and gives the error – **OAuthException: An unexpected error has occurred. Please retry your request later.Fatal error: Uncaught OAuthException: An unexpected error has occurred. Please retry your request later thrown in /sdk/base_fac
apaul34208
php class codeigniter
Basically I have a helper file with several function. I auto load the helper in the config file so theoretically reloading it is not required.However when I try to use the function that I created(from this helper) within a new library that I am working on it will through this error:”Parse error: syntax error, unexpected ‘(‘, expecting ‘,’ or ‘;’ in /home/techwork/public_html/giverhub/application/libraries/Udetails.php on line 7″Whenever I use that function anywhere else(module,controller,views)
khellang
php javascript jquery ajax
Basically I am trying to post a comment via AJAX and then load the new comment into the HTML. I am having a problem with what I think is my AJAX success function. The data gets added to the database fine, but I still get an error “Sorry, unexpected error. Please try again later.” as set inside the success function itself.JS:function newComment(event) { event.preventDefault();//Get the data from all the fieldsvar comment = $(‘textarea’);var product_id = $(‘input[name=product_id]’);var form
Zack Morris
php bash cli shell-exec suppress
If you create a simple php script with this code:shell_exec(‘”‘);And run it with:php myscript.phpIt gives the following error in bash on my Mac:sh: -c: line 0: unexpected EOF while looking for matching `”‘ sh: -c: line 1: syntax error: unexpected end of fileI’ve tried everything I can think of:ob_start(); @shell_exec(‘”‘); ob_end_clean();@shell_exec(‘” 2> /dev/null’);But no matter what I try, I can’t suppress the message. The problem is that I’m creating a unit test to stress test $argc, $ar
Jeff Hines
php eval anonymous-function preg-replace-callback
I’m getting this error, but I cannot find out why:Parse error: syntax error, unexpected $end in C:\wamp\www\test.php(19) : eval()’d code on line 1Any insight would be appreciated!$table = ‘<table><tr><td>${Q*10}</td></tr></table>’;$symbols = array(‘Q’ => 10);preg_replace_callback(‘/\${(\w+)([*+-\/])(\d+)}/’, function($matches) use ($symbols, $table) {return repl($matches, $symbols, $table); }, $table);function repl($tokens, $symbols, $table) {$replace = ar
ChemBlob9999
javascript ajax performance anonymous-function
This question already has an answer here:Does it matter which equals operator (== vs ===) I use in JavaScript comparisons?24 answersMy site has several ajax functions essentially identical (except different variable names, etc.) to the following:function ajaxFunction(string) { var ajaxRequest;try {ajaxRequest = new XMLHttpRequest();} catch (e) {try {ajaxRequest = new ActiveXObject(“Msxml2.XMLHTTP”);} catch (e) {try {ajaxRequest = new ActiveXObject(“Microsoft.XMLHTTP”);} catch (e) { alert(“Your
Codemonkey
php anonymous-function
Possible Duplicate:Workaround for basic syntax not being parsedWhy dont PHP attributes allow functions? I’m gettingParse error: syntax error, unexpected T_FUNCTION in /home/codemonkey/dev/broadnet/bito.api2/broadnet/resources/broadmapresource.php on line 87From this code:private $debugFunctions = array(“testing” => function() // Line 87{return “I’m a test function!”;},”foo” => function(){return “bar”;} );I was under the impression I could use anonymous PHP functions anywhere I could use $
rybosome
php closures anonymous-function reduce
I’m trying to execute the following PHP code:$path_hierarchy = // function that returns an arrayreturn array_reduce($terms,function($val1, $val2) use ($path_hierarchy) {return $val1 || in_array($val2, $path_hierarchy);} );…but I’m getting the following PHP error:PHP Parse error: syntax error, unexpected ‘)’, expecting ‘{‘So, I switched to the following syntax:$path_hierarchy = // function that returns an array$callback = function($val1, $val2) use ($path_hierarchy) {return $val1 || in_array($
hakre
php anonymous-function
I am trying to realize my own MVC framework and invented a very nice way to provide definitions of virtual fields and additional relations.According to some other high-voted post on stackoverflow, this should actually work:class User extends Model {public $hasOne = array(‘UserSetting’);public $validate = array();public $virtualFields = array(‘fullname’ => function () {return $this->fname . ($this->mname ? ‘ ‘ . $this->mname : ”) . ‘ ‘ . $this->lname;},’official_fullname’ => fu
Otiel
c# linq foreach extension-methods anonymous-function
I ran into what was to me an unexpected result when testing a simple ForEach extension method.ForEach methodpublic static void ForEach<T>(this IEnumerable<T> list, Action<T> action) {if (action == null) throw new ArgumentNullException(“action”);foreach (T element in list){action(element);} }Test method[TestMethod] public void BasicForEachTest() {int[] numbers = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };numbers.ForEach(num =>{num = 0;});Assert.AreEqual(0, numbers.Sum()); }Wh
BoltClock
javascript parsing syntax grammar anonymous-function
If I try to execute a script whose only source line is an object:{prop:’value’}it parses fine (in both V8 and UglifyJS). Similarly I can put a string or number on its own as source code and there is no syntax error reported.However, both V8 and UglifyJS complain about this on its own:function(){}I get Uncaught SyntaxError: Unexpected token (.Why does this break when the object in the first example is fine? Aren’t functions just objects in javascript?I realise declaring an anonymous function with
psionicgames
javascript angularjs anonymous-function
I am using angularjs and would like to pass an anonymous javascript function from an html element’s ng-click function as a parameter to a function on my scope. I have setup up a simple jsfiddle to demonstrate the problem: http://jsfiddle.net/C4t4LystX/gUj8x/4/. Whenever I try and do this in my code I get this type of error in the console: Syntax Error: Token ‘{‘ is unexpected, expecting [)] Any help or insight on how this can be accomplished would be appreciated.
Dan Lugg
php types closures anonymous-function
To quote PHP:Anonymous functions are currently implemented using the Closure class. This is an implementation detail and should not be relied upon.Now, that said, the following checks are deemed unreliable:function myFunction(Closure $callback){}if(!($callback instanceof Closure)){}Which brings us to using is_callable(). This is fine, however if one requires a true “closure”, (as an argument, or what-such) then is_callable() isn’t strict enough. The following of course dumps bool(true) for each:
ash
php anonymous-function
I’m trying to use array_walk with an anonymous function, but I always get the error // Parse error: syntax error, unexpected T_FUNCTION in … on line Xif(!empty($myArray)) {array_walk($myArray, function(&$value, $key){ // Line X$value = ‘”‘.$value.'”‘; // Add quotes});}The surrounding file syntax is correct. Any thoughts?
Web site is in building