Module 7 – PHP Functions and Rollover Images

This week we covered PHP functions and rollover images. My web page for the assignment is here:

http://jered.0fees.us/module7/index.php

Web programming section

I used a simple function and if/else block for the web code. The syntax was fairly similar to other languages.

One thing that struck me right off the bat was that an error in PHP code could cause the page to fail to load – omitting a semicolon yielded a 500 server error. JavaScript is more forgiving, just skipping that code instead of blocking the whole page.

Another difference is the way variable scope is handled. As I recall, JavaScript will use a variable from outside a function simply by referencing it, while in PHP you have to explicitly import a global variable into a function.

The if statement seems to work similarly in both languages. Function definitions are also similar between the two, with both languages being loosely typed and not defining return types.

Web design section

For the web design portion, we needed to add an image to a page that would change when someone hovered the cursor over it. I went looking for a way to do it with CSS, using :hover, and that started looking a bit complicated. Then I came across some simple JavaScript to do the same thing (using onmouseover and onmouseout to change the image displayed via this.src). Then I kicked myself for not thinking to check JavaScript first, and went with that approach. The HTML is much easier to read with the JavaScript approach.

This entry was posted in Web Design Technologies. Bookmark the permalink.

Comments are closed.