print

print

PHP Question: Print Object

Question

The following code was executed.

<?php
class MyClass {
  private $foo = "bar";
}

$myObject = new MyClass();
echo $myObject;

Which produced the following error.

Catchable fatal error: Object of class MyClass could not be converted to string in test.php on line 7

Call Stack:
    0.0011     323736   1. {main}() /test.php:0

How can the code be simply changed to prevent this error and produce some form of result?

PHP Question: Printing A Boolean Value

Question

What will the following code print, and why?

echo TRUE;

Get Child Pages List In Wordpress

It is possible to print out a list of pages in Wordpress, but these functions are designed to print from the root pages to a certain level. I often need to print out a list of pages that are children of the current page being looked at so I created the following function.

Create A Tag Cloud Page In Wordpress

A tag cloud is a name for a collection of keywords that are displayed as a big block of text. Usually the most commonly occurring keyword is the largest, and the least commonly occurring keyword is the smallest. Tag clouds are a neat way of allowing your users to navigate your content in a different way, simply be letting them look over the cloud and linking each keyword to sections of your site that contain that word.

Displaying Wordpress Authors

Wordpress has a couple of rarely used functions that allow author information to be displayed for the current post and a list of all of the authors on the blog.

Adding a written by message to your posts is not difficult at all. Just use the the_author_posts_link() function inside the post loop.

<?php the_author_posts_link(); ?>

This function shouldn't be confused with the the_author_link() function that prints out the link in the author's profile.

Write To The Output Buffer In PHP

The first thing you learn about in PHP is probably how to print something. This is usually done with a call to the echo or print, but there is another way to print things by writing content directly to the output buffer. The following code looks like you are writing to a file, but the text will appear in the browser window because we are writing to the php://output output stream.

$fp = fopen("php://output", 'r+');
fputs($fp, "Hello World");

Or another way...