Skip to content

Tag: php

Accessing a public/private function inside a static function?

Due to the fact that you can not use $this-> inside a static functio, how are you supposed to access regular functions inside a static? This throws an error, because you can’t use $this-> inside a static. This throws the following error: How can you access regular methods inside a static method? I…

PHP array unique by column

How to filter an array to give unique elements according to one or more columns. Example: If we choose type and type2 as the unique column. The result of the algorithm should gives I can think of an algorithm by hashing the type concatenate with type2, store in a table and using isset to find the existence. B…

PHP getting days of a month for a database

I’m making a calender planner with php/css/javascript/html. I am trying to set each day of the month a class which is “day”. I tried using the following: It does not work correctly, it kept duplicating every month and I am not sure how to correctly right the php to achieve what was intended.…

PHP, $this->{$var} — what does that mean?

I have encountered the need to access/change a variable as such: The context is with CI datamapper get rules. I can’t seem to find what this syntax actually does. What do the {‘s do in this context? Why can’t you just use: Answer This is a variable variable, such that you will end up with $t…

“no acceptable variant” from MultiViews in Apache

In one deployment of a PHP-based application, Apache’s MultiViews option is being used to hide the .php extension of a request dispatcher script. E.g. a request to …would be handled by …with the trailing part of the request URI available in PATH_INFO. Most of the time this works fine, but oc…

Is it wrong to use a hash for a unique ID?

I want to use a unique ID generated by PHP in a database table that will likely never have more than 10,000 records. I don’t want the time of creation to be visible or use a purely numeric value so I am using: Is it wrong to use a hash for a unique ID? Don’t all hashes lead to collisions

Reading from STDIN pipe when using proc_open

I am trying to make a website where people can compile and run their code online, thus we need to find an interactive way for users to send instructions. Actually, what first comes to mind is exec() or system(), but when users want to input sth, this way won’t work. So we have to use proc_open(). For in…

Why does PHP compact() use strings instead of actual variables?

Can anyone explain the benefit of PHP’s compact() function accepting the string of ‘a variable with that name’ instead of the actual variable? For example: Why do I need to pass a string of the variable name instead of just passing the variable itself and PHP handling mapping this to an arra…