views:

78

answers:

1

Ok, so here's the quick rundown. I have a function to generate the page numbers.

This:

<?php
die($ani->e->tmpl->pages("/archive", 1, 15, 1, true));
?>

will output Single Page like expected.

But this:

<?php
$page_numbers = $ani->e->tmpl->pages("/archive", 1, 15, 1, true);
?>
<?= $page_numbers ?>

will output a simple 1 to the page. Why is it getting converted to a 1? I would expect it to store the 'Single Page' string to the page_numbers variable and then output it (like an echo) exactly the same.

EDIT: Running a var_dump($page_numbers) returns int(1)...

Here is the entire function in context:

<?php
// other functions...
function show_list() {
    global $ani;
    $page_numbers = $ani->e->tmpl->pages("/archive", 1, 15, 1, true);
    ob_start();
?>
<!-- content:start -->
<?php
    $archive_result = $ani->e->db->build(array("select" => "*", "from" => "animuson_archive", "orderby" => "0-time", "limit" => 15));
    while ($archive = $ani->e->db->fetch($archive_result)) {
?>
<h2><a href="/archive/article/<?= $archive['aid'] ?>/<?= $archive['title_nice'] ?>"><?= $archive['title'] ?></a></h2>
<!-- breaker -->
<?php
    }
?>
<?= var_dump($page_numbers) ?>
<!-- content:stop -->
<?php
    $ani->e->tmpl->process("box", ob_get_clean());
}
// other functions...
?>
+2  A: 

$page_numbers is an integer in both examples. Something else is going on. You'll need to post the code of the pages() method. I suspect the ob_start() is doing something weird, since passing integer 1 to die() will never print that 1 (it will exit with return code 1).

PS: Why can't I make a comment like everyone else?

d11wtq
You don't have a high enough rep level. http://stackoverflow.com/faq
Jeff Rupert
Moreso, I bet if you put the var_dump() right before the die() you'll see that it is indeed int 1 and that die() is dying correctly (silently) and causing PHP to exit with return code 1.
d11wtq
Ah thanks, so I need a rep of 50 to leave a comment. It seems weird since I'd have thought leaving a half-assed answer would be more disruptive than leaving a half-assed comment. Anyway, best not take this off-topic :)
d11wtq
I don't think you understood what I was doing with die. I was simply modifying the line where it sets the page_numbers variable. I took off the '$page_numbers = ' part and enclosed the function in die to see what it was returning, and it would output 'Single Page' which is the string that the function IS returning.
animuson
Nevermind, I think I may have figured out what it is. I don't remember what I did, but something caused it to output 'Single Pageint(1)' which wehn I thought about your comment made me think that 'Single Page' was being outputted somewhere and then var_dump was outputting the 'int(1)' but I can't figure out where it's getting outputted.
animuson
Yeah that's what I was thinking "Single Page" was/is being output from somewhere else entirely. Grep your code for "Single Page" and see where it's occurring? Maybe you left some debug info somewhere and forgot about it.
d11wtq
Well I know where it's coming from, the problem is figuring out why it's being sent to the browser rather than being returned with the function. It's echoed in the page_numers.php style file, which is run by a 'return require' command so anything that is echoed should be returned as a string. It's a lot of code and aside from giving you access to the files I can't think of any good way to get it all here.
animuson
You'll need to post the relevant code. We don't have that here.
d11wtq
I just figured it out, the required file wasn't running the output buffering correctly so it was just outputting the data rather than returning the buffer, therefore the require function was returning 1. Thanks for the start, though.
animuson