# Object-Oriented Programming in WordPress: Types

This post is part of a series called Object-Oriented Programming in WordPress.
Object-Oriented Programming in WordPress: Classes
Object-Oriented Programming in WordPress: Control Structures I

For those who are just starting this series, note that we are taking a look at object-oriented programming using PHP within the context of WordPress.

## The Target Audience

We're doing so from the perspective of the very beginner, so if you're an experienced developer, or are familiar with many of the aspects of object-oriented programming, then this series is probably not for you.

With that said, if you are interested in learning object-oriented programming in PHP and you do consider yourself a beginner, then we're going to continue the series in this article by talking about some of the data types that PHP offers.

But first, make sure that you've caught up on the previous articles in the series as they each build on one another:

Once you're all caught up, we can begin talking about types.

## What Are Types?

We ended the last article with the following:

We'll get to that, but first we need to discuss some of the more primitive aspects of programming such as strings, arrays, loops, and conditionals.

Now, strings, arrays, and so on are what we consider types. Loops and conditionals are what are known as control structures which we'll be covering in the next article.

So in the meantime, let's come up with a simple term for what a data type represents so that we know how to conceptually model them moving forward not only with this article, but with the rest of the content in the series.

For anyone who has written any code that includes variables, then you've likely seemed something like the following:

• $name = 'Tuts+ WordPress'; • $is_active = true;
• $age = 42; • ...and so on. In the most basic form, you'll likely hear the above code defined as variables with definitions, and that's correct, but it's a very generalized definition. You see, whenever you define a variable in PHP, you so by prefixing the variable with $. This lets PHP know that you're defining a variable, and that it will represent a typical value.

Easy enough, right?

The thing is, there are different types in PHP. For those who are coming from what are known as "strongly-typed languages," we'll talk about that more momentarily, but know that PHP offers the following data types:

• booleans
• integers
• floating point numbers
• strings
• arrays
• objects
• ...and more

Everything from booleans through strings can be thought of as a simple data type where as arrays and objects can be considered more complex data types.

### Simple Data Types

Simple data types are defined as such because the data that they represent is, y'know, simple. That is to say that it will normally fall under the banner of true, false, decimals, and words and/or sentences.

To give concrete examples of each of the above:

• Boolean values are intended to hold the value of true or false.
• Integers refer to any whole numbers. That is to say that it includes no fractional or decimal components to it. This includes numbers such as -12, -2, 1, 100, 5000, and so on.
• Floating Point Numbers are kind of the opposite of Integers in that they do represent values with fractional parts. So, for example, you may see 3.1459, 2.5, 100.25, and so on. If you were to try to save the value of, say, 3/4 then you'd actually save .75 unless you saved it as a string. That is, you were to save '3/4'. Notice the subtle delineation between the two? One has quotes and one does not.
• Speaking of strings, strings represent any single word or set of alphanumeric characters that make up a series of letters and numbers. This may be a single word, it may be sentence, it may be sentences, and it may be a random series of characters such as an encrypted string. Examples of strings include 'phrases like this' or a single 'word' or even something more complex like 'e952098vjdkw94kd'

Here's the catch, though—any of the above data types can be converted into strings by wrapping them in quotation marks.

### But There's a Catch

For example, if you were to work with the boolean value of, say, true but you were to store it in a variable like this: $is_active = 'true'; then you've actually just created a string that reads true. Similarly, if you were to write a string that read $age = '42'; then you've created a string containing the number 42not an integer.

Make sense?

The reason that this matters is because when it comes time to working with control structures—which we'll review in the next article—is that sometimes, running comparison can have unintended consequences if you're not sure which data type with which you're working.

### Complex Data Types

In addition to simple data types, we also have complex data types which, in my opinion, aren't really that complicated. In fact, I think of it as a fancy way of saying that we have ways of storing multiple pieces of information into a single variable; whereas, with simple types, we have a way to store single pieces of information in a single variable.

Pretty easy to remember, right? So what are some of the more complex data types?

The two primary complex datatypes that we're going to focus on in this series as arrays and objects. There are more, but they are outside the scope of this series, so if you're interested, then feel free to take a look at the PHP manual, but I warn you: if you're an absolute beginner, the content may feel a little overwhelming.

## Where To Next?

Before we return to the world of object-oriented programming, we need to talk about a a few additional basic structures of programming such as control structures.

These include things such as loops, conditionals, and so on that can impact the flow of code throughout the lifetime of the program. Additionally, they work hand in hand with the data types that we've outlined here.

So before we head into the next article, make sure that you review everything that's going on here, leave comments, questions, and feedback in the comment feed.

I'll see you in the next article!