[icon] Makes you like your eggs on the Jersey side
View:Recent Entries.
View:Archive.
View:Friends.
View:User Info.
View:Website (Clowns Will Eat You).
View:Poly Geek Relationship Disclosure Form.
You're looking at the latest 16 entries.

Tags:, ,
Subject:I am employed again!
Time:06:36 pm
Current Mood:[mood icon] excited
However, for only 8 weeks. it's a PHP gig, and it sounds like pretty simple stuff - developing web forms to insert into a MySQL database. But my team will have to do the lot - design the DB and the forms - so that will be fun. And I'm going to try and teach them the wonders of Smarty. Which I'm not completely in love with, but it's pretty good.
comments: 2 comments or Leave a comment Add to Memories Tell a Friend

Tags:, ,
Subject:[CODE] This acually works!
Time:10:15 am
Current Mood:[mood icon] surprised
<?php
   
  foreach(array('emp', 'mgr') as $prefix) {
      $data[($prefix == 'emp') ? 'employee' : 'manager'] = 1;
  }
  
  print_r($data);
?>


Output:

Array
(
    [employee] => 1
    [manager] => 1
)


I would have expected that from Perl, but not PHP.

EDIT: added output per [info]aisa0's request. :)
comments: Leave a comment Add to Memories Tell a Friend

Tags:, , , , ,
Subject:[CODE] PHP is still pass-by-copy
Time:05:19 pm
Current Mood:[mood icon] disappointed
I had it in my head that with PHP5, objects were implicitly passed by reference. contrast this with PHP4, in which objects were implicitly passed by silent copy (I don't know how deep, though). This code demonstrates that objects are still implicitly passed by copy, and that annoys me.

*sigh* After having done a lot of OO Perl for the past month and a half, coming back to PHP OOP is a bit of a letdown.

PHP code behind the cut )
comments: Leave a comment Add to Memories Tell a Friend

Tags:,
Subject:Looking for PHP coders
Time:08:53 am
The company I work for, Monolith Software Solutions, is looking for PHP programmers. Interested? Drop me a line: user "kpeters", domain "monolithss (dot) com".

(x-posted to my LJ, and [info]charleston_sc)
comments: Leave a comment Add to Memories Tell a Friend

Tags:, ,
Subject:[GEEKY] Interesting PHP tidbit
Time:11:42 am
Say you have some class, call it Foo, with a protected member $bar. In PHP 5.2.0, you can do this:

class Foo {
  
  protected $bar = 'bak';

  public baz() {
    $foo = new Foo;
    print "\$foo->bar: {$foo->bar}\n";
  }

}


Doesn't that violate the spirit of making something protected?
comments: Leave a comment Add to Memories Tell a Friend

Tags:, ,
Subject:GEEKY: PHP and subclassing
Time:03:55 pm
Current Mood:geeky
Say the parent class and the subclass both define a non-abstract method foo(). Say also that parent class and subclass both override __get(), and ParentClass::__get calls foo() for some property 'bar'. ParentClass::foo() (and thus SubClass::foo()) must be declared protected for parent::__get('bar') to call SubClass::foo(). IOW, you can't really override private methods.

I did not know that.
comments: Leave a comment Add to Memories Tell a Friend

Tags:, , , , , ,
Current Music:The voices in my head
Current Location:Vaticanus Scurrilous Twoninefourohsevenus
Subject:GEEKY: MySQL and updating tables
Time:06:15 pm
Current Mood:perplexed
If I perform an UPDATE query on an InnoDB table in MySQL 5.0, is it guaranteed that the next time I read data from the table, the updated data shows up in the affected rows? If not, how do I make sure that this happens?

I'm having a problem at work where even though I've done an UPDATE to a certain table via a Perl script, and the Perl script has (I think) exited before I'm reading it from PHP, the updated data are not read by the PHP application. When I go in and look using the MySQL command-line client, however, the data are there. I'd rather not have to tell the user, "If you don't see any data, hit the reload button." It's just tacky.
comments: Leave a comment Add to Memories Tell a Friend

Tags:, ,
Subject:(GEEKY) A great big WTF?!?!?!?!?
Time:09:29 am
Current Mood:[mood icon] shocked
Apparently, automatically converting an object to an integer in PHP results in a 1....
code behind the cut )

This is just categorically wrong.

EDIT: This page sheds some light on this behaviour. It seems that in the case of a data type other than strings and floats, the item is first evaluated as a boolean, and then converted to integer. So since an object instance evaluates to boolean true, the subsequent integer conversion evaluates to 1.

Still not what I would have expected.
comments: Leave a comment Add to Memories Tell a Friend

Tags:, ,
Subject:GEEKY: HTTP POST
Time:02:21 pm
Is it the defined behaviour of forms submitted via POST that any checkbox that is not checked is not submitted? IOW, say we have this tag:

<input type="checkbox" name="foo" id="foo" value="1" checked="checked" />

and the user unchecks it. Rather than something to the effect of "foo=0" being sent via POST, is there simply not supposed to be an item named "foo" in POST?

I ask this because it's happening to me in PHP - if 'foo' is unchecked, $_POST['foo'] is not set. Is this the defined/expected behaviour of HTTP? I haven't found anything either way in the PHP docs.
comments: Leave a comment Add to Memories Tell a Friend

Tags:, , ,
Subject:GEEKY: My coding philosophy (in part)
Time:02:25 pm
I say "in part" because I don't know if I can fully describe it. :)

Also, this is only going to apply to writing PHP/XHTML/Javascript, because that's what I've been doing lately at work. I know that I'm walking down the path of the applications/UI programmer, rather than the systems programmer, to use Wayne's classes of programmer, but that's where the work is right now.

In no particular order:


  1. HTML should pass validation by The W3C Markup Validation Service. My personal preference is for XHTML 1.0 Strict, or XHTML 1.1, but I can't honestly say that I have any reason for preferring them over HTML 4.01. Whatever is used, though, it should validate against the standard, because the standard is what browser authors use, or at least ought to be using, to write their parsing and rendering engines, and I believe that if one sticks to the standard, one runs the least risk of the newest revision of some browser breaking their code.

  2. One should not embed HTML in PHP, nor embed PHP in HTML. This is a special case of my general belief in separating application logic from presentation logic. There are several template engines for PHP (Smarty being my engine of choice), and there is no reason that I can see not to use them. It enhances the readability of your code, which is important when you or someone else goes back and looks at it two years later.

  3. Indent your code. Indentation and appropriate use of whitespace make code very readable, and it's important that you and other people be able to read your code.

  4. Comment your code. I use phpDocumentor because it generates nicely formatted HTML documentation. Commenting your code gives the reader some idea of whatever it is the code is supposed to do.

  5. Document your code's public interface. This is sort of a special case of the previous item. Define the way you want your code to be interfaced with. Once your public interface is defined, then you can go and change anything behind the scenes to your heart's content, so long as it stays compatible with the public interface. This also means that if someone uses some undocumented feature of your code, and said undocumented feature goes away, the onus is on the caller to fix their code.

  6. Don't use undocumented features of your or anyone else's code. That's just a recipe for disaster, for similar reasons as described in the previous item.



Now I realize that these are ideals, and there may be situations where it becomes necessary to violate some or all of them. There are also several items in which all I've done is "passed the buck" - the ideal only gives you justification for saying "it's not my fault; make someone else do it." This is also not always feasible in the real world. That said, as a programmer, your time is valuable, and you shouldn't be wasting time fixing other people's mistakes if you can avoid it.

Finally, remember the Three Virtues: Laziness, Impatience, and Hubris.
comments: Leave a comment Add to Memories Tell a Friend

Tags:, ,
Subject:GEEKY: PHP and exceptions
Time:04:07 pm
I've been pushing PHP's exception framework, because I thought it was a good idea. I like being able to throw exceptions. But exceptions that don't tell you where they were thrown are fucking useless. God damn it, I don't want to rewrite all my code.

UPDATE: Well, I was able to subclass Exception and create a version that tells me where the error happened. Still annoyed that I had to do it.
comments: Leave a comment Add to Memories Tell a Friend

Tags:, ,
Subject:GEEKY: PHP and private constructors
Time:02:48 pm
In PHP 5.1.2, when you extend a class, you apparently can't strengthen the access level of a constructor, e.g. if you have a base class with a public constructor, your derived class can't have a private constructor. This is annoying me mightily.
comments: Leave a comment Add to Memories Tell a Friend

Tags:, ,
Subject:GEEKY: onPHP
Time:09:14 pm
Tell me about onPHP.
comments: Leave a comment Add to Memories Tell a Friend

Tags:, ,
Subject:GEEKY: Well, that's annoying
Time:05:21 pm
Apparently I can't create inner or anonymous classes in PHP 5.0.4. Dammit.

And don't tell me I should use something other than PHP. We use PHP at work, and there's nothing I can do about it, so I'm stuck writing PHP.

*growl*
comments: Leave a comment Add to Memories Tell a Friend

Tags:, ,
Subject:GEEKY: w00t!
Time:09:29 am
I can now create PGP encrypted/signed e-mail messages of the proper (RFC2015) MIME type: "application/pgp-encrypted" and send them out, all via PHP, and they're readable and decryptable by a 3rd party mail client (KMail.) I'd love to test it out on some other clients, though - if you want me to send you a test message, post your public key (or a link to your public key) in the comments. My public key is in my userinfo.
comments: Leave a comment Add to Memories Tell a Friend

Tags:,
Subject:GEEKY: PECL docs
Time:05:18 pm
This one's for the PHP folk reading this LJ. Where do I go to find documentation for a given PECL package? I know I can just go digging around in the source, but it seems like there ought to be some central place for the docs to live, like with PEAR packages.
comments: Leave a comment Add to Memories Tell a Friend

[icon] Makes you like your eggs on the Jersey side
View:Recent Entries.
View:Archive.
View:Friends.
View:User Info.
View:Website (Clowns Will Eat You).
View:Poly Geek Relationship Disclosure Form.
You're looking at the latest 16 entries.