php5

Implications of Instantiating Objects with Dynamic Variables in PHP

What are the performance, security, or "other" implications of using the following form to declare a new class instance in PHP <?php $class_name = 'SomeClassName'; $object = new $class_name; ?> This is a contrived example, but I've seen this form used in Factories (OOP) to avoid having a big if/switch statement. Problems that...

Get MIME type of a local file in PHP5 without a PECL extension?

mime_content_type() is deprecated. How can I find the MIME type of a local file using PHP5 but without using this deprecated method or the PECL fileinfo extension? Edit: That's what I was afraid of. It's unfortunate that they deprecated a built-in function in favour of one that requires an extension that isn't always available. ...

Best way to hide DB connection code in PHP5 for apps that only require one connection?

Below I present three options for simplifying my database access when only a single connection is involved (this is often the case for the web apps I work on). The general idea is to make the DB connection transparent, such that it connects the first time my script executes a query, and then it remains connected until the script termina...

In PHP5, should I use Exceptions or trigger_error/set_error_handler ?

What are the pros/cons of doing either way. Is there One Right Way(tm) ? ...

How do I access class variables of a parent object in PHP?

An instance of class A instanciates a couple of other objects, say for example from class B: $foo = new B(); I would like to access A's public class variables from methods within B. Unless I'm missing something, the only way to do this is to pass the current object to the instances of B: $foo = new B($this); Is this best practice...

PHP - command line arguments in Windows

I'm trying to run PHP from the command line under Windows XP. That works, except for the fact that I am not able to provide parameters to my PHP script. My test case: echo "param = ".$param."\n"; var_dump($argv); I want to call this as: php.exe -f test.php -- param=test But I never get the script to accept my parameter. The r...

How to create a DOM from a User's input in PHP5?

I can't seem to find any decent info about this on the web. Any advice? ...

Is there any way to detect the target class in PHP 5 static methods?

Below is an example class hierarchy and code. What I'm looking for is a way to determine if 'ChildClass1' or 'ChildClass2' had the static method whoAmI() called on it without re-implementing it in each child class. <?php abstract class ParentClass { public static function whoAmI () { // NOT correct, always gives 'ParentCl...

Where would you advertise for a UK based telecommuting PHP developer?

This is not an advert - it's where would you put an advert for the best effect. Clarification: it's a employer aiming to find a new (full-time) employee. ...

PHP equivalent of Perl's 'use strict' (to require variables to be initialzied before use)

Python's convention is that variables are created by first assignment, and trying to read their value before one has been assigned raises an exception. PHP by contrast implicitly creates a variable when it is read, with a null value. This means it is easy to do this in PHP: function mymodule_important_calculation() { $result = /* .....

Tidy Converting <Span Style="Font-Style:Bold"> to <Class="C1">.

I am using the PHP 5 Tidy class to format html. Everything is fine except when it gets passed a style attribute, when it changes it into a class attribute. As I am only formatting the body of a document, not the head, there is no class defined in the head for the attribute to read. I have looked through all the Tidy options but can't ...

Dynamic class variables

Does PHP have a method of having auto-generated class variables? I think I've seen something like this before but I'm not certain. public class TestClass { private $data = array(); public function TestClass() { $this->data['firstValue'] = "cheese"; } } The $this->data array is always an associative array but they ...

Stored Procedures, mySQL and PHP5

The question is a fairly open one. I've been using Stored Procs with MS SQLServer for some time with classic ASP and ASP.net and love them, lots. I do have a small amount of experience with PHP4 and mySQL, and previously when working with these was limited to in-line SQL. I have a small hobby project I'm working on and for various rea...

PHP __destruct() method

In PHP5, is the __destruct() method guaranteed to be called for each object instance? Can exceptions in the program prevent this from happening? ...

PHP: self vs this

In PHP5, what is the difference between using self and $this? When is each appropriate? ...

Zend PHP5 Certification, does it matter?

The Zend PHP5-certification, is it really worth it? In the end for me it boils down to: Will it get me jobs I wouldn't without it? ...

PHP5: Specifying a datatype in method parameters

I have a function that looks like this class NSNode { function insertAfter(NSNode $node) { ... } } I'd like to be able to use that function to indicate that the node is being inserted at the start, therefore it is after nothing. The way I think about that is that null means "nothing", so I'd write my function call like...

Custom Filters/Validators in Zend Framework

I have a Zend Framework application structure as below: /application /library /Zend /Core /Filter /MyFilter.php /Validator /MyValidator.php I would like to put custom filters and validators in their respective folders and have them loaded automatically when used. However, I cannot figure...

PHP 5.x syncronized file access (no database)

Hi, I'm mostly familiar with Java, C and C++ in which there are ways to control that only one thread is accessing a resource at any given time. Now I'm in search for something similar but in PHP 5.x. To formulate my problem with one example: I have an ASCII-file which only stores a number, the value of a page load counter. At applicat...

How to link to a gzipped javascript in an html document?

I've seen a number of references to gzipping a javascript to save download time. But I also see a number of warnings that certain browsers do not support this. I have two different methods at my disposal: use mod_deflate to make Apache compress JS/CSS files in a given directory through htaccess use ob_start('gzhandler') to compress a...