Categories > TinyButStrong general >

script= with key=val (Bug/Feature)?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: mgb
Date: 2007-12-20
Time: 16:02

script= with key=val (Bug/Feature)?

Hi All
I have something like this
$sum_of_all = 2775;

[onshow;script=dostuff.php;subtpl;total=[var.sum_of_all;noer;ifempty=0];noerr]
in my template
and in dostuff.php
I have $CurrPrm['total'] = '2775';
now if I try to do a is_numeric on it will return false
if I try to do a settype() it will change the value to 0;
same if I try $CurrPrm['total']++; it will have the value 1 after the operation.
if I do a serialize on it it will report: s:32:"2667";
I have even tried to do $tmp = $CurrPrm['total'];
but then $tmp reacts the same even.
Does anyone have any idea whey this variable is so special?
By: TomH
Date: 2007-12-20
Time: 18:36

Re: script= with key=val (Bug/Feature)?

AFAIK anything in quotes/semiquotes is by definition a char string.

Maybe use settype() to force var type
By: mgb
Date: 2007-12-20
Time: 19:07

Re: script= with key=val (Bug/Feature)?

Hi TomH
I tried forcing it with a settype() but it set the variable to 0.
I know variables in quotes are strings but normally you can type cast them with (int) or indeed settype()
but non of them works.
Still didn't figure it out.
By: TomH
Date: 2007-12-20
Time: 20:51

Re: script= with key=val (Bug/Feature)?

If you're getting '0' as a displayed value -- my guess ;) is that means 'false' not zero.
This works.  Notice that settype does not set type if before the var's value is set
settype($num,"int");
$num='2775';
echo "<BR>\$num= ".$num." and gettype= ".gettype($num)."<BR>";
settype($num,"int");
echo "<BR>\$num= ".$num." and gettype= ".gettype($num)."<BR>";
By: mgb
Date: 2007-12-21
Time: 09:43

Re: script= with key=val (Bug/Feature)?

Hi TomH,
Thanks for trouble shooting with me :)

The problem is that I am using this in a subscript. So I already have the variable in $CurrPrm['total'];
Observe the following
subscript.php
if(isset($CurrPrm['total'])) {
    echo '|'.gettype($CurrPrm['total']).'|';
    echo '|'.serialize($CurrPrm['total']).'|';
    echo '|'.$CurrPrm['total'].'|';
    echo '|'.($CurrPrm['total']+0).'|';
    echo '|'.(int)$CurrPrm['total'].'|';
    echo '|'.serialize($CurrPrm['total']).'|';
    settype($tmp,'int');
    $tmp = $CurrPrm['total'];
    echo '|'.serialize($CurrPrm['total']).'|';
}
will produce
|string||s:32:"2667";||2667||0||0||s:32:"2667";||s:32:"2667";|
what also puzzles me is the s:32? in the serialize output.
echo serialize('lala');
// would normaly produce
// s:4:"lala";

I am beginning to think this is a php bug?
By: mgb
Date: 2007-12-21
Time: 09:44

Re: script= with key=val (Bug/Feature)?

last serialize should be on $tmp (same result)
By: mgb
Date: 2007-12-21
Time: 09:55

Re: script= with key=val (Bug/Feature)?

the s:32 does lead me to think its a utf8 encoding problem but I have also tried
echo '|'.serialize(utf8_decode($CurrPrm['total'])).'|';
with the same result.

I am at lost ends ?
By: TomH
Date: 2007-12-21
Time: 14:27

Re: script= with key=val (Bug/Feature)?

The sequence of the settype() was the point I was tryting to make earlier
Like this...
if(isset($CurrPrm['total'])) {
    echo '|'.gettype($CurrPrm['total']).'|';
    echo '|'.serialize($CurrPrm['total']).'|';
    echo '|'.$CurrPrm['total'].'|';
    echo '|'.($CurrPrm['total']+0).'|';
    echo '|'.(int)$CurrPrm['total'].'|';
    echo '|'.serialize($CurrPrm['total']).'|';
    $tmp = $CurrPrm['total'];  // this line BEFORE settype()
    settype($tmp,'int');
    echo '|'.serialize($tmp).'|';
}
This works, unless I misunderstand still.
By: TomH
Date: 2007-12-21
Time: 14:32

Re: script= with key=val (Bug/Feature)?

Sorry forgot to show my result
|string||s:4:"2667";||2667||2667||2667||s:4:"2667";||i:2667;|
The last set shows the  |i:2667| where $tmp is now integer after the settype() line
By: TomH
Date: 2007-12-21
Time: 14:41

Re: script= with key=val (Bug/Feature)?

Furthermore - arithmetic on the $tmp var does work as expected. Adding the following code to the above...
    echo '|'.($tmp+13).'|';
    echo '|'.gettype($tmp).'|';
Gives the expected...
|string||s:4:"2667";||2667||2667||2667||s:4:"2667";||i:2667;||integer||2680||integer|
Hope that helps
By: mgb
Date: 2007-12-21
Time: 14:50

Re: script= with key=val (Bug/Feature)?

Hi TomH,
Nope this doesnt make a difference. if you look at your output of serialize it gives you s:4 while mine is s:32. its in there the problems lie.
I believe it has to do with my templates being unicoded. But how to fix it I have no idea.

Could you see if you could reproduce it?
ALL files MUST be unicoded
caller.php
$array[] = 1;
$array[] = 2;
$array[] = 3;
$sum_of_all = count($array);
$tbs->LoadTemplate('template.tpl','UTF-8');
$tbs->MergeBlock('test',$array');
$tbs->Show();

template.tpl
[onshow;script=callie.php;subtpl;total=[var.sum_of_all;noer;ifempty=0];noerr]

callie.php
echo '|'.serialize($CurrPrm['total']).'|';

Note: This is a simplification of my scripts so I am not sure this will have the same effect but it should.
By: mgb
Date: 2007-12-21
Time: 15:24

Re: script= with key=val (Bug/Feature)?

TBS/PHP voodoo:
this subtpl script runs:
if(isset($CurrPrm['total'])) {
    echo '|'.serialize($CurrPrm['total']).'|';
    echo '|'.serialize(substr($CurrPrm['total'],0,24)).'|';
}
And out-puts:
|s:32:"2667";||s:24:"[var.total_gals;noerr;if";|
Now if that isnt Voodoo I don't know what is :)

as seen above my [onshow...] has
total=[var.total_gals;noerr;ifempty=0]
the [] included gives total a lenght 32 charactors :)
I am guess now that this has to do with php references, still its Voodoo :)
By: TomH
Date: 2007-12-21
Time: 16:32

Re: script= with key=val (Bug/Feature)?

Well... I think I have some info that might help you or Skrol29 to find the inner problem.

The diff between your code (not working) and my similar code (which was working for me) is thatI was testing by setting the param directly not from a TBS var.
To see the diff... try testing with something like the equivalent of

template.tpl
[onshow;script=callie.php;subtpl;total=3300]

Skrol29 might be able to help from here, but I'm out of brainpower at this point, sorry.
By: mgb
Date: 2007-12-21
Time: 16:58

Re: script= with key=val (Bug/Feature)?

Thanks for all your help TomH,
I think between us two we got narrowed it down to something to do with php references .... and voodoo.
By: TomH
Date: 2007-12-21
Time: 20:51

Re: script= with key=val (Bug/Feature)?

I don't understand exactly why this works this way (we need Skrol29 for this one) but look at this...
caller.php
$array = array(
array("key"=>"8"),
array("key"=>"3"),
array("key"=>"4"),
array("key"=>"5"),
array("key"=>"6"));

$sum_of_all = count($array);
//$sum_of_all = 77;

$tbs = new clsTinyButStrong ;

$tbs->LoadTemplate("template.tpl");
$tbs->MergeBlock('test',$array);
$tbs->Show();

template.tpl
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>caller.php (template.tpl)</title>
</head>
<body>
We'll position the subscript here for convenience...<P>
[onload;script=callie.php;subtpl;total=[var.sum_of_all];]
<P>
We'll position the caller.php/template.tpl output here...<P>
<hr size=3 color=red>
<ul>
<li>rec [test.#] has [test.key;block=li;] items</li>
</ul>
<hr size=3 color=red>
TBS v.[var..version]
</body>
</html>

callie.php
global $const;
global $numplus;
global $sum_of_all;

//$num = $CurrPrm['total'];
$const=1000;
//$numplus = $const + $num;
$numplus = $const + $sum_of_all;

$this->LoadTemplate("callie.html");
$this->Show();

callie.html
<HR color=blue size=3>Don't ask...<HR size=5>
Total= [var.sum_of_all]
<br>Const= [var.const]
<br>Total + Const = [var.numplus]
<HR color=blue size=3>
Notice that I am calling the "sum_of_all" variable directly -not via the CurrPrm() array.
Like I said... don't ask!
But be advised I'm using TBS v.3.2.0
More voodoo I guess...
By: Skrol29
Date: 2007-12-27
Time: 10:16

Re: script= with key=val (Bug/Feature)?