I've been very, VERY slack the last couple of years and let this site stagnate. However, I've made a conscious decision to actively start doing some programming again in my spare time, something I haven't done in a very long time, I've become very lazy in my old age.
Okay so it's been a bloody long time since I posted, but I have been brain bleeding busy at work and my girlfriend has joined me in Cape Town, so my free time mostly consists of spending it with my gf, friends or relaxing.
Anyway just a quick post on naming of variables.
If you want to make it easier for designers to create a page, but you want to hide the complexities of the php from them, then you could quite possibly use the operator
$$. A quick example code before I explain:
$variableName = "myVar"; $data = "Here is some data"; $$variableName = $data;
So I'm back with my Back to basics series of posts. In part 1, we dealt with what PHP is and how it works and in part 2 we dealt with the very basics of variables and functions. Now in most programming tutorials, you'll usually deal with variable types, control statements, loops and the such (we're getting there), before you do functions, but because of the way PHP works and the way it sets its' variables, I decided to do basic functions before everything else.
In this post, we're going to take a closer look at variables and then we'll move onto control structures, loops and how variables are evaluated.
Hey all, it's been a while since my last blog post, sorry for that, been rather busy at work and at home at the same time, so haven't even had much time to even think about content for a post.
So we're back with the Back to basics series of posts that I had promised, this being part two of who knows how many. In this post I'm going to try and cover the very basics of programming in PHP. I'm going to try and keep the concepts pretty general though, so you can apply them to any structured programming language.
So I'm still helping my friend out with some captcha stuff and we've hit a small problem with one of the image functions. I start talking to another friend of mine, scuzzy (Daine), about the problem and he suggests I use another function. Basically the line of code that wasn't really working was this one:
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
Daine suggested I just use the
imageline() function, but make it reall small, so it looks like a dot (we settled on imageputpixel though, but thats got nothing to do about it).
imageline() needs an extra two x/y params, but in our case, they have to be the same as the original to simply create a dot. But I'm lazy and I hate lots of lines of code, so I rekon I'll do it the dirty way.
She was saying that she would actually like to learn how to code in PHP and that she'll take some courses at some stage. I said she should just go through the php.net site and go through the documentation, as there is some good stuff on there to start off from. I found myself explaining alot of the very basics of PHP though, how it is translated, why it needs to run on a web server, etc. I decided then to make a small series of blog posts covering the very basics of the PHP web language, which is where we are now... Part 1.
Okay, so I promised some wordpress and CSS stuff, but the CSS stuff will have to wait for a while, till I’ve got some time to actually write up the essay that it’s going to probably be. Instead I’ll quickly go through a problem I had today with wordpress.
I’ve was asked to quickly put together a site for a client that my company has. They were asking for a quick turn around and they were specific in what theme and plugins/widgets they wanted. One of the requirements was that they’re able to capture extra info during the user registration process, but they also wanted it to look the same as the wordpress theme. Currently, if you theme your page, but go to the login page, you're greeted with the dull standard wordpres page and logo. So installed ‘theme-my-login’ and ‘register-plus’ which helped me achieve these things.
So I’m back with part two of my problems I’ve had with polymorphism. In part one I talked about ways of getting around not being able to assign a base class to a derived class (of that base class). Previously, I said that all you need to do is just assign all variables and such in a constructor to the new class variables, thereby making a “copy” of the class.
While this sort of works in theory, it doesn’t quite work in practice. It’ll work with simple classes, or classes that you design to work that way, but it’s not really what I wanted.
What I wanted isn’t really good practice, so now I’m going to show you how I really ended up creating my extended classes for the mysqli libraries. I’m just going to work with the mysqli and mysqli_stmt objects, but you can apply the same concepts to other objects.
So I've recently moved back to South Africa from London and I've been looking for work. My core roles over the years have been as an IVR (Interactive Voice Response) Developer. Now days, these systems are all voice XML and you get to work in Java, but the companies I've been working for all use proprietary hardware and proprietary languages, which is all fine and dandy for IVR, but doesn't translate well into transferable skills for the developer. However, if you need anything done outside of the IVR environment, you end up working in other languages, so I've ended up with some working experience in PHP/C/C++/Java/C#/SQL/etc.
Anyway, as I was saying, I'm back from London, looking for work in Cape Town. I've looking to Focus in either PHP or C# as its the two languages I enjoy the most and find I work well in the environments. So I went to a job interview for a PHP web developer position and the interview goes well and they send me a test. In the test, it asked you to use concepts like arrays, loops, objects, etc. Now, I’ve worked with objects before and got the basic concepts down (I think), but I keep running into things I don’t know.
So I’ve decided to take the mysqli objects that are used to connect and communicate with a mySQL database and extend them with my own class that simply calls the old object, but throws exceptions instead of returning errors, I’ll refer them as wrappers from now. It’s not going to change the world or anything, but it gave me a chance to learn some things about objects in PHP, as I hadn’t done much of it.
I had created a wrapper for the mysqli and
mysqli_stmt objects. The problem I came into when I tried to extend the to create my own prepare statement function. In the function I called
mysqli::prepare function, which returns a
mysqli_stmt object. Of course, I don’t want a
mysqli_stmt object, I want my wrapper statement object. I thought I could just cast it to my wrapper statement object.
I thought wrong.