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

learn more… | top users | synonyms

61
votes
21answers
29k 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 ...
49
votes
6answers
49k 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 <? ?> ...
46
votes
4answers
70k 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 ...
43
votes
13answers
9k 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(){ ...
39
votes
5answers
82k 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 ...
37
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 ...
34
votes
6answers
19k 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 ...
33
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 ...
31
votes
12answers
12k 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 ...
31
votes
7answers
22k 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 ...
28
votes
15answers
2k 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
6answers
13k 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 ...
27
votes
10answers
6k 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 ...
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
3answers
11k 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 ...
25
votes
14answers
2k views

What shall I include in a 10 week web technologies course? [closed]

In September I will be teaching a university module on web technologies. This session will be available to 1st year (freshman) students who don't necessarily have any programming knowledge or know ...
25
votes
6answers
18k views

How can I apply OOP concepts to building a simple, but real-world, web app?

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 ...
23
votes
9answers
10k 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 ...
23
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 ...
22
votes
5answers
9k 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 ...
21
votes
3answers
8k 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 ...
20
votes
10answers
2k 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
9answers
33k views

Type Casting variables in PHP: Is there a practical example?

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 ...
19
votes
5answers
6k 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. ...
18
votes
6answers
14k 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 ...
18
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 ...
17
votes
6answers
1k 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
7answers
3k 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 ...
17
votes
12answers
6k 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?;" ...
17
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
3answers
2k 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
8answers
6k 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 ...
16
votes
5answers
19k 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 ...
16
votes
7answers
3k 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
4answers
19k 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, ...
15
votes
7answers
4k 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 ...
15
votes
5answers
13k views

Why is PHP so frequently used on web servers?

My web server uses PHP as do 76.9% of web servers according to W3Techs: http://w3techs.com/technologies/overview/programming_language/all The reason I use PHP is an inertia born out of seeing ...
15
votes
4answers
6k 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 ...
15
votes
1answer
888 views

Dollar Sign Blues: Javascript and PHP

I grew up programming C++ and Java where everything was safe and beautiful. Compilers made sure to keep me in check if I ever strayed. Of course, everyone did a little Perl in college, but I didn't ...
14
votes
2answers
2k views

Illegal in PHP: Is there an OOP design reason?

The below interface inheritance is illegal in PHP, but I think it would be fairly useful in real life. Is there an actual antipattern or documented problem with the below design, that PHP is ...
14
votes
5answers
23k 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 ...
14
votes
4answers
21k views

Why did Facebook use C++ beside PHP?

What is the main reason that made Facebook need to use C++ beside PHP? I am wondering if I make a website with alot of vistors would I need to use C++ as well?
14
votes
2answers
22k 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. ...
13
votes
7answers
11k views

Confused about ASP.NET Ajax, jQuery and JavaScript [closed]

Yesterday, I read couple of chapters on ASP.NET Ajax and jQuery from my ASP.NET 4 book and I found those frameworks pretty interesting and decide to learn more about them. Today, I borrowed some ...
13
votes
2answers
1k views

Is an NPath complexity of over sixteen octillion realistic? Or have I broken the tool?

I have just measured a large chunk of PHP code (1153 lines) using PHPMD (http://phpmd.org/) and it tells me the code has an NPath complexity of 16244818757303403077832757824. That looks like a ...
13
votes
5answers
5k 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: ...
13
votes
5answers
5k 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 ...
13
votes
2answers
51k 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 ...
13
votes
4answers
867 views

What to do when your company doesn't encrypt passwords

Background I'm been contracted to help a company maintain their server. I work on some minor PHP projects but also look over performance issues and recently, scan logs for hackers. These guys have ...