Questions about PHP, a widely-used general-purpose scripting language that is especially suited for Web development.

learn more… | top users | synonyms

109
votes
7answers
8k 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 ...
93
votes
7answers
80k 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 <? ?> ...
88
votes
64answers
14k 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 ...
63
votes
21answers
35k 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 ...
53
votes
12answers
3k views

How do you control code quality on your team? [closed]

Here is my situation. After almost 2 years I was able to convince my boss to use TDD, version control, coding standards for the entire team and a MVC framework for our web projects. I was finally ...
48
votes
4answers
90k 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 ...
46
votes
13answers
13k 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(){ ...
42
votes
5answers
99k 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....
37
votes
16answers
3k 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
7answers
26k 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 ...
36
votes
6answers
32k 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 ...
36
votes
11answers
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 ...
35
votes
7answers
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 ...
35
votes
6answers
24k 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 ...
35
votes
7answers
49k 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 ...
34
votes
13answers
30k 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 ...
32
votes
12answers
14k 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 ...
29
votes
6answers
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 ...
28
votes
15answers
3k 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 ...
27
votes
10answers
7k 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 ...
27
votes
4answers
33k 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, ...
27
votes
3answers
14k 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 ...
26
votes
10answers
4k 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 ...
26
votes
5answers
9k 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. ...
26
votes
5answers
12k 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 ...
25
votes
5answers
22k 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 ...
24
votes
3answers
9k 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 ...
24
votes
6answers
1k 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 ...
23
votes
9answers
11k 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
6answers
9k 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 ...
22
votes
1answer
16k 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 ...
21
votes
10answers
3k views

Struggling as a programmer. Need some advice [closed]

I've been a developer now for a number of years. I'm pretty good at what I do and can "get the job done". But, there is a difference between "getting the job done" and "doing the job properly". Let's ...
20
votes
6answers
40k 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 ...
20
votes
8answers
7k 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 $...
19
votes
7answers
6k 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 ...
19
votes
2answers
32k 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. ...
19
votes
12answers
7k 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?;" ...
19
votes
5answers
3k views

Your experience with haxe and other languages that compile to PHP?

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 ...
18
votes
7answers
6k views

How to break the “php is a bad language” paradigm? [closed]

PHP is not a bad language (or at least not as bad as some may suggest). I had teachers that didn't even know PHP was object oriented until I told them. I've had clients that immediately distrust us ...
18
votes
8answers
3k views

What would you consider best practice workflow tools for web application (PHP) development? [closed]

I'm really hoping somebody with more experience can edit the question as per my examples of answers: using version control test driven development debugging code (xdebug for php) use of UML diagrams ...
17
votes
6answers
2k views

Best way to plan programming for small teams? [closed]

I am the Director of a small startup organisation. We currently have two programmers (one experienced, one less experienced) who are building a web application platform. One of the greatest ...
17
votes
5answers
25k views

Why is Python slower than Java but faster than PHP [closed]

I have many times seen various benchmarks that show how a bunch of languages perform on a given task. Always these benchmarks reveal that Python is slower then Java and faster than PHP. And I wonder ...
17
votes
3answers
19k views

PHP web application architecture/design [closed]

I've been thrown head-first into a new job developing web applications in PHP. I'm by no means new to PHP, but I haven't developed large-scale applications before. I'm wondering how to structure my ...
17
votes
3answers
68k 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 ...
17
votes
5answers
7k views

Directly modifying superglobals

I've seen people (who generally write good code) directly alter the $_POST array with code like this: // Add some value that wasn't actually posted $_POST['last_activity'] = time(); // Alter an ...
17
votes
3answers
3k views

How to design website workflow?

I have been thinking about this for really long time without reaching an optimum answer. First of all, I'm a medical doctor who loves programming but never really studied it, except for home learning ...
16
votes
7answers
4k views

Is it possible to effectively develop PHP applications on Windows that will be deployed on servers running Linux?

Is it fine to code PHP on Windows and host it later on a server running Linux? Can there be any problems in the migration of such a project? I would think that there really can't be any problems, ...
16
votes
2answers
1k views

Is it a good idea to define one big private function in a class to maintain valid state, that is, to update the object's data members?

Although in the code below a simple single item purchase in an e-commerce site is used, my general question is about updating all data members to keep an object's data in valid state at all times. I ...
16
votes
4answers
2k views

Why exactly can't PHP have full unicode support?

Everybody knows, that PHP has problems with Unicode. Version 6 is effectively abandoned, because of Unicode implementation difficulties. But I wonder if anyone knows what are the exact reasons? ...
16
votes
1answer
2k views

I've unit tested my class, now how do I get started with an integration test?

I've written a class that manages recipients on a MailChimp list, called MailChimpRecipient. It uses the MCAPI class, which is an third-party API wrapper. http://apidocs.mailchimp.com/api/1.3/ http://...