Questions tagged [php]
Questions about PHP, a widely-used general-purpose scripting language that is especially suited for Web development.
2,041
questions
211
votes
8
answers
205k
views
Is it bad practice to use <?= tag in PHP?
I've come across this PHP tag <?= ?> recently and I am reluctant to use it, but it itches so hard that I wanted to have your take on it. I know it is bad practice to use short tags <? ?> ...
109
votes
7
answers
9k
views
You're hired to fix a small bug for a security-intensive site. Looking at the code, it's filled with security holes. What do you do? [closed]
I've been hired by someone to do some small work on a site. It's a site for a large company. It contains very sensitive data, so security is very important. Upon analyzing the code, I've noticed it's ...
94
votes
5
answers
99k
views
Naming classes, methods, functions and variables [duplicate]
There are 3 important naming conventions:
with_underscores
PascalCased
camelCased
Other variants are not important because they are not commonly used.
For variables it seems that the one with ...
88
votes
63
answers
15k
views
What features would you like to have in PHP? [closed]
Since it's the holiday season now and everybody's making wishes, I wonder - which language features you would wish PHP would have added? I am interested in some practical suggestions/wishes for the ...
66
votes
4
answers
104k
views
What's the dominant naming convention for variables in PHP: camelcase or underscores? [closed]
The consensus seems to be that one should follow the convention of the platform they're developing for. See:
Underscore or camelcase?
Naming conventions: camelCase versus underscore_case?
However, ...
65
votes
21
answers
43k
views
"Don't do programming after a few years of starting career". Is this a fair advice? [closed]
I am a little experienced developer having approximately 5 years experience in PHP and somewhat less in Java, C# and trying to learn some Python nowadays. Since the start of my career as a programmer ...
59
votes
12
answers
33k
views
Is it considered bad practice to have PHP in your JavaScript
So many times on this site I see people trying to do things like this :
<script type="text/javascript">
$(document).ready(function(){
$('<?php echo $divID ?>').click(funtion(){
...
58
votes
3
answers
112k
views
How can I test PHP skills in a interview? [closed]
My company needs to hire a PHP developer, but nobody has PHP knowledge in my company and we find difficult to test for PHP skills. If it were a C/Java developer I would ask him to write a quick ...
55
votes
11
answers
11k
views
Is there a general solution to the problem of "sudden unexpected bursts of errors" in software?
Let me explain what I mean.
I have made a complex, highly polished over years PHP framework/library for my own use. I very aggressively log the smallest notice and immediately deal with it as soon as ...
49
votes
5
answers
24k
views
should I throw exception from constructor?
I know I can throw exception from constructor in PHP but should I do it? For example, if a parameter's value is not as I expected it.
Or should I defer throwing an exception till a method is invoked. ...
46
votes
8
answers
9k
views
Is it common practice to validate responses from 3rd party APIs?
I'm working on a PHP web application that depends on a few 3rd-party services. These services are well documented and provided by fairly large organisations.
I feel paranoid when working with ...
46
votes
5
answers
122k
views
When to use PHP or ASP.NET? [closed]
I have worked extensively in developing web applications using PHP and ASP.NET, but one of the questions that I'm constantly asked by customers is whether to move forward with a php website or an asp....
45
votes
7
answers
91k
views
Type casting variables in PHP, what is the practical reason for doing this?
PHP, as most of us know, has weak typing. For those who don't, PHP.net says:
PHP does not require (or support) explicit type definition in variable declaration; a variable's type is determined by ...
44
votes
6
answers
35k
views
Why does Facebook convert PHP code to C++? [closed]
I read that Facebook started out in PHP, and then to gain speed, they now compile PHP as C++ code. If that's the case why don't they:
Just program in c++? Surely there must be SOME errors/bugs when ...
42
votes
7
answers
33k
views
Why is Zend Framework so complicated?
I am web developer and have experience of developing several web applications in PHP. I have an idea of developing a product for myself and decided to use a MVC based framework because I really like ...
42
votes
2
answers
48k
views
PHP: when to use arrays, and when to use objects for mostly-data-storing code constructs?
PHP is a mixed paradigm language, allowing to use and return non-object data types, such as arrays. I pose a question to try to clarify some guidelines for selection of arrays vs objects when deciding ...
41
votes
10
answers
16k
views
What is so bad with goto when it's used for these obvious and relevant cases?
I have always known that goto is something bad, locked in a basement somewhere never to be seen for good but I ran into a code example today that makes perfect sense to use goto.
I have an IP where I ...
41
votes
2
answers
67k
views
Why PHP doesn't support function overloading?
I am wondering if one of the key features of a programming language is to have the ability to overload functions via arguments. I think it is essential in-context of the Object oriented programming.
...
40
votes
7
answers
10k
views
Why do library developers deliberately break existing code?
Today, I updated ZBateson\MailMimeParser the PHP e-mail parser library from 1.x to 2.x.
Soon enough, my PHP error log started filling up with errors.
Noting where it happened, I found out that it had ...
38
votes
11
answers
3k
views
Why isn't protection against SQL injection a high priority?
On Stack Overflow, I see a lot of PHP code in questions and answers that have MySQL queries that are highly vulnerable to SQL injection attacks, despite basic workarounds being widely available for ...
37
votes
16
answers
4k
views
Does it hurt to learn bits of many programming languages?
I started my programming career with BASIC, during 9th grade. I learned a bit of BASIC by writing simple programs to add, subtract and to print. Then I went to the university and took Computer ...
37
votes
6
answers
17k
views
Why is using 'final' on a class really so bad?
I am refactoring a PHP OOP legacy website.
I am so tempted to start using 'final' on classes to "make it explicit that the class is currently not extended by anything". This might save lots of time ...
36
votes
7
answers
4k
views
Is there a need to keep tests for simple (self-contained) functions?
Consider this:
public function polynominal($a, $b, $c, $d)
{
return $a * pow($x, 3) + $b * pow($x, 2) + $c * $x + $d;
}
Suppose you write various tests for the above function and prove to ...
34
votes
13
answers
40k
views
Career advice: stay with PHP or start a new career in something else ( .Net?) [closed]
I'm planning on moving to NY in 6-12 months tops, so I'm forced to find a new job. When I'm planing to start my life in another city it's also probably a good time to think about career changes.
I've ...
34
votes
9
answers
11k
views
Is it good practice to echo PHP code into inline JS?
I'm new to PHP and JS and I'm currently working on a gym management web app for our project in school. I'm adding a bit of QR functionality that sees if the user is eligible to enter the gym or not by ...
34
votes
7
answers
92k
views
Which is better: to include HTML inside PHP code or outside it?
Look at this:
<?php
echo "Hello World";
?>
<br />
<?php
echo "Welcome";
?>
And now look at this:
<?php
echo "Hello World";
echo "<br />";
echo "Welcome";
?>
Which one ...
34
votes
11
answers
20k
views
Why does PHP have interfaces?
I noticed that as of PHP5, interfaces have been added to the language. However, since PHP is so loosely typed, it seems that most of the benefits of using interfaces is lost. Why is this included in ...
34
votes
3
answers
24k
views
How to build completely modular web applications [closed]
In the coming months we're going to begin a project where we take a system we've built for a client (v1) and rebuild it from scratch. Our goal with v2 is to make it modular, so that this specific ...
33
votes
1
answer
34k
views
With PHP frameworks, why is the "route" concept used?
The reason I ask this is because isn't a PHP script a route? For example, if you have an article.php then your route is simply http://mysite.com/article.php.
Why further abstract away the concept of ...
30
votes
7
answers
16k
views
Why are references rarely used in PHP?
I have some C++ knowledge and know that pointers are commonly used there, but I've started to look at PHP open source code and I never see code using references in methods.
Instead, the code always ...
30
votes
6
answers
14k
views
Should I choose Doctrine 2 or Propel 1.5/1.6, and why? [closed]
I'd like to hear from those who have used Doctrine 2 (or later) and Propel 1.5 (or later). Most comparisons between these two object relational mappers are based on old versions -- Doctrine 1 versus ...
30
votes
2
answers
16k
views
What are the different meanings of 'fixture'?
I have some difficulty understanding the concept of "fixture". I know what a test suite is, a test case, a test run,
but what exactly is a "fixture"? A parameterized test case?
It seems to me that ...
28
votes
15
answers
4k
views
Is it wise to be going back and forth between two programming languages? [closed]
I have been writing quite a lot of PHP for nearly two years. Now I am doing .NET (mainly c#) development. However, sometimes I go back and do some php.
My main question is, is it wise for me to ...
28
votes
10
answers
8k
views
What is good (neat) architecture in programming a simple website, e.g. a contact book?
When I build a simple website, e.g. a contact book where I can add, delete and update contacts, I create an index.php file where a user, if he's not logged in, is requested to enter a password and if ...
28
votes
5
answers
20k
views
What best practices should be employed in a PHP login script?
I am wanting to re-write my login scripts for clients websites to make them more secure. I want to know what best practices I can implement into this. Password protected control panels are in their ...
27
votes
10
answers
5k
views
How do I pitch ASP.NET over PHP to a potential client? [closed]
I work at a Microsoft shop doing mainly web development.
We had a client who asked us to review (improve) the data model for his web app, but said that he wants to develop his app in PHP (he knows "a ...
27
votes
9
answers
14k
views
Why do many PHP Devs hate using isset() and/or any of PHP's similarly defensive functions like empty()?
Over on stackoverflow, I see this issue crop up all the time:
E_NOTICE ?== E_DEBUG, avoiding isset() and @ with more sophisticated error_handler
How to set PHP not to check undefind index for $...
27
votes
6
answers
3k
views
How to properly take over a complex PHP project [duplicate]
I've been tasked to correct some issues on the backend of a large website project that has been outsourced for some time. The original developers and us are not on good terms so it's not feasible to ...
26
votes
3
answers
13k
views
I'm trying to understand hash tables - can someone explain it to me - clearly?
I want to understand the correct use and implementation of hash tables in php (sorry).
I read somewhere that an in-experienced programmer created a hash table and then iterated through it. Now, I ...
25
votes
5
answers
31k
views
How can I apply OOP concepts to building a simple, but real-world, web app? [closed]
I've been trying now for a long time to wrap my head around OOP. I see its advantages. I've read many, many tutorials and watched an equal amount of videos on the subject. I get the animal/cat/dog ...
25
votes
5
answers
26k
views
Multiple arguments in function call vs single array
I have a function that takes in a set of parameters, then applies to them as conditions to an SQL query. However, while I favored a single argument array containing the conditions themselves:
...
25
votes
3
answers
94k
views
Datetime vs Timestamp in MySQL and PHP in practice?
I am not sure how to specify my datatype as datetime or timestamp, I think I will need both of them but on the different events. My website sells products and services worldwide and also have an ...
23
votes
9
answers
15k
views
Should I build my own CMS or rely on a pre-built one? [closed]
Related: As a beginning programmer, should I favor building my own libraries over using 3rd-party libraries?
As an intermediate to advanced level PHP web-developer and a young one at that (15yrs.), ...
23
votes
4
answers
11k
views
Store images in the database, or in files with a database link?
Is it appropriate to store the image files in the database? Or it would be better to store only the path of the file in the database, while keeping the file itself on the server?
Are there any other ...
23
votes
6
answers
6k
views
Your experience with haxe and other languages that compile to PHP? [closed]
I would like to hear opinions from people who have used a language that compiles to php. One such language I know is Haxe. Other ones I've read about are Kira and Pharen.
How well do these languages ...
22
votes
7
answers
27k
views
Should I encrypt data in database?
I have a client, for which I'm going to do an Web application about patient care, managing patients, consults, history, calendars, everything about that basically.
The problem is that this is ...
22
votes
2
answers
16k
views
Exceptions in DDD
I'm learning DDD and I'm thinking about throwing exceptions in certain situations. I understand that an object can not enter to a bad state so here the exceptions are fine, but in many examples ...
22
votes
12
answers
11k
views
How to write a command interpreter/parser?
Problem: Run commands in the form of a string.
command example:
/user/files/ list all;
equivalent to:
/user/files/ ls -la;
another one:
post tw fb "HOW DO YOU STOP THE TICKLE MONSTER?;"
equivalent ...
22
votes
2
answers
43k
views
What kind of license to put a private project?
The project in which work is private for commercial purposes and not its source code is distributed to anyone. Only the functional application shown consumers through a website.
It has the following ...
21
votes
3
answers
7k
views
Is it good practice to avoid warnings and notices?
I've generally been working with PHP warnings and notices off, since I work on a lot of projects where it's already in live production. Now, if I turn on the warnings and notices on these live ...