Testing slib ‘scriptify’ and friends

I’ve written a few little functions to help me sanitise content before including it in automatically generated JavaScript. The idea is to prevent code injection.

You can see the tests for my function in the scriptify_test.php file on ProgClub Member Net (where jsphp.co is hosted). You can view the scriptify unit tests in pcrepo.

Unit testing is fun! :)

Strings in PHP

I’ve been looking into how strings work in PHP. Basically if you use a single quote the string is literal and the only two quotes accepted are \\ for backslash and \’ for single quote.

If you use double quotes on the other hand then backslash is the quote character so you can do things like \n for new line or \t for tab. Also you can use variable names in double quotes strings. I still don’t totally understand things like magic quotes work though.

Regular Expressions (Perl-Compatible)

I found the documentation for regular expressions at php.net.

I read somewhere on the internet to use the pattern modifiers “msU” to match multiline content, but while I understand the ‘m’ and the ‘s’ I don’t understand the ‘U’ very well. I’m not sure what it means to be greedy or ungreedy exactly. But I’ve been using msU pattern modifiers in my regexps that parse the phpjs.org content for import into jsphp.co.

uniqid, usort, create_function, strcasecmp

I found out about a PHP function uniqid. You can see an example of its output on my test page.

Other functions that I’ve learned recently are usort, create_function and strcasecmp.

I also learned that if you want to link to the PHP function documentation you can use a link in the form http://php.net/function_exists where ‘function_exists’ is the function name you’re interested in.

Doctrine column types

I’m using Doctrine 2.1, and the only documentation I could find for column types in Doctrine was in the 1.2 documentation. I’ve been trying to use the ‘clob’ data-type that is listed there, but haven’t had any luck getting it to work. So what I’ve done instead is to use a ‘string’ data-type and override its columnDefinition with something like this:

@Column(type="string", nullable=false, columnDefinition="TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL")

It’s a pain because that causes the database updating script below to output column changes every time it is run:

php %doctrine% orm:schema-tool:update --dump-sql > update.sql