[PHP] Freeing memory for DOMDocument

2009-01-07 Thread Christoph Boget
I'm running through a large dataset and am generating/manipulating XML
documents for each record.  What's happening is that after a while, I
get a fatal error saying:

Fatal error: Allowed memory size of 167772160 bytes exhausted (tried
to allocate 32650313 bytes)

Each XML file I generate (an manipulate) can range from just a few
megs to upwards of 35 megs.  Judging from the error above, it looks
like the memory for the DOMDocument objects I instantiate is not
getting freed; it just continues to stay in memory until the memory is
completely exhausted.  The method (in my object) I am using to
instantiate a new DOMDocument is as follows:

protected function createCleanDomDocument()
{
/*
  if(( isset( $this->oDomXPath )) && ( !is_null( $this->oDomXPath )))
  {
unset( $this->oDomXPath );
  }

  if(( isset( $this->oDomDocument )) && ( !is_null( $this->oDomDocument )))
  {
unset( $this->oDomDocument );
  }
*/
  $this->oDomDocument = new DOMDocument( '1.0', 'iso-8859-1' );
  $this->oDomXPath= new DOMXpath( $this->oDomDocument );
}

which is used in both the constructor of my object and in a few other
places.  I would think that when the new DOMDocument is instantiated,
the memory used for the old value would get freed.  As you can see,
I've even tried to unset the variables but that doesn't seem to help
matters much, either.

Does anyone know how (or even if) I can explicitly free the memory
used for the DOMDocument?  Any help/advice would be greatly
appreciated!

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Freeing memory for DOMDocument

2009-01-07 Thread Christoph Boget
>> Does anyone know how (or even if) I can explicitly free the memory
>> used for the DOMDocument?  Any help/advice would be greatly
>> appreciated!
> I've had exactly the same problem and couldn't find a way around it; even
> after unsetting every variable in my scripts inside a for/while loop; in the
> end I opted for a CLI script which opened worker threads then
> killed/restarted them when memory usage was X.

Unfortunately, that is not an option for me.  It just blows my mind
that a method to free memory used for a DOMDocument object wasn't
built in... :|

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Create image from HTML

2009-01-09 Thread Christoph Boget
Does anyone know if it's possible, using PHP, to take HTML (either as
an input or from a URL) and generate an image (essentially, create a
screenshot) of that HTML/page?  I've looked around but was unable to
find anything and I'm just not sure if it's that there really is
nothing like this out there or if I'm just looking in the wrong
places.

Any advice/suggestions would be greatly appreciated!

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Making a Variable from different tables with Matching Db fields?

2009-01-28 Thread Christoph Boget
> Well I'm stuck I have the AdminID but now I can't seem to use it to pull
> workorders with that AdminID . I couldn't get your block to work Andrew :(
> I think I'm just not using it right now that I have it...lol

Because there is ambiguity w/r/t the columns you are selecting, you'll
need to use aliases.

http://dev.mysql.com/doc/refman/5.1/en/identifiers.html

In your code, when you are referencing the column, do so using the
alias.  That should solve your problem.

thnx,
Christoph


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Making a Variable from different tables with Matching Db fields?

2009-01-28 Thread Christoph Boget
> >> Because there is ambiguity w/r/t the columns you are selecting, you'll
> >> need to use aliases.
> >> http://dev.mysql.com/doc/refman/5.1/en/identifiers.html
> >> In your code, when you are referencing the column, do so using the
> >> alias.  That should solve your problem.
> > I just read it 3 times and I don't understand it.
> Try this... (just make sure to assign a valid $username value.)
> $sql =
> "SELECT workorders.WorkOrderID , workorders.AdminID
> FROM workorders
> INNER JOIN
>   admin
> ON  workorders.AdminID = admin.AdminID
> WHERE admin.UserName = '" . mysql_real_escape_string($username) . "'";

Andrew is right.  If you use the above query, that will probably get you
going.  But in general, aliases allow you to reference a column as
something other than what it is named in the table's schema.  It would
allow you to do something along the lines of:

SELECT
  Employee.Name AS EmployeeName,
  Employer.Name AS EmployerName
FROM
  blah blah blah.

In the above example, the column "Name" is ambiguous.  By defining an
alias, it removes the ambiguity and allows mysql to return the value of
both columns.  In your code, you would just reference it using:

$rowData['EmployeeName']
$rowData['EmployerName']

I hope that helps explain aliases a bit.

thnx,
Christoph


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Looking for some PHP OO programming guides

2009-02-11 Thread Christoph Boget
> > How can you require 8 levels of nesting? surely there must be something
> > wrong or a more efficient algorithm...
> No! It's just that you can't think in 8 dimensions like him.

Yeah, at that point you are dealing with space and time and that's not a
subject of contemplation for everyone. :p

thnx,
Christoph


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Namespce operator

2009-03-25 Thread Christoph Boget
>> Backslash? Seriously? I'm hurt that my suggestion of "¬" (ASCII170 ?)
>> wasn't used. :-(
> Backslash doesn't sound like it will look very pretty

Windows and DOS have been getting away with it for the last 25+ years
so why can't PHP get in on that action? :P

Though I have read the explanation (many, many times) and I still
don't understand why '::' wasn't used.  MyClass::MyStaticMethod is
utilizing namespacing.  Why it was felt that '::' as the official
namespace operator would mess that up is beyond my ken. :(

thnx,
Christoph

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Symlinks and ownership

2009-04-23 Thread Christoph Boget
Is there a reason why you can't programatically set ownership of a
symbolic ink?  The following code

if( symlink( TARGET, LINK ))
{
  echo 'Successfully created ' . LINK . "\n";

  if( @chown( LINK, NEW_UID ))
  {
echo 'Successfully changed ownership for ' . LINK . "\n";

if( @chgrp( LINK, NEW_UID ))
{
  echo 'Successfully changed group for ' . LINK . "\n";

}
  }
}

echos out:

Successfully created XXX
Successfully changed ownership for XXX
Successfully changed group for XXX

yet when I go take a look at it in the directory, the group for the
link has not been changed to what I set it to.  Is that not something
you can do for symbolic links programatically?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Warning: Division by zero

2009-04-30 Thread Christoph Boget
> I have a script that is a result of data entered in a form
> On the script (when I test without data entry), I am getting a warning that
> Warning: Division by zero in .inc.php on line 15.
> The warning is correct, however the viewer cannot access the second script
> without entering the data that would cancel the warning.
> Is this something I should worry about? or would it be better to right in an
> isset?

Well, just as a general rule, you'll want to validate all possible
user input.  That includes checking whether or not particular input
has been defined, whether or not it is valid for it's intended use and
whether or not it's malicious.

Applying that guideline to your situation, I would check to see if:

* the input is set
* the input is numeric

If either or those are not true, I would default the value to 1 since
division is being used. e.g.,

$iVar = 1;
if(( isset( $_REQUEST['MY_NUMBER'] ) && ( is_numeric(
$_REQUEST["MY_NUMBER']))) {
  $iVar = $_REQUEST['MY_NUMBER'];
}

$iCalculatedValue = $x / $iVar;

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Warning: Division by zero

2009-04-30 Thread Christoph Boget
> The error I am getting is when I am defining a variable.
> (line 15) $percent_difference=($assess_difference)/($assess_value);
> Does this make a difference?

No, it doesn't make a difference.  The simple fact is that
$assess_value is either undefined or has been set to 0 at some point.
For it's use in the above equation, neither case is valid.
Consequently, you really should be doing some validation at some point
prior to that line.

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Does something like this exist?

2009-06-29 Thread Christoph Boget
I'm wondering if there isn't something out there that crawls through
your codebase and generates a map of (any of) the following:

* What files are include in which scripts
* The relationships between defined classes (eg A extends B)
* What other classes are utilized by which classes (eg, instantiation)

I've done some looking around but haven't really been able to find
anything that does even some of this.  I could write functionality
that does this but didn't want to reinvent the wheel.

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Does something like this exist?

2009-06-29 Thread Christoph Boget
>> * What files are include in which scripts
> pecl.php.net/package/inclued  - an awesome tool, will show you
> includes/require calls to other ones, show you any redundancy (dotted
> lines) etc. helps you clean up any nested and unnecessary includes or
> requires. Rasmus approved(tm)
> use it with graphviz and you've got visual maps of your entire
> include/require structure.

Ok, I'll look in to it.  Thanks!

>> * The relationships between defined classes (eg A extends B)
>> * What other classes are utilized by which classes (eg, instantiation)
> doesn't phpdoc or something do this stuff? might need comments before
> each function/method to make it really work well. not sure. i think
> there's also something called "phpxref" as well that might work...

It does.  But I'm looking to use this on an inherited framework that,
unfortunately, includes very little PHPDoc comments.  Considering how
large the codebase is, it'd be quicker for me to write this
functionality (to at least give us something to reference) than it
would be to add the necessary comments.  Granted, that's something
we'd want to eventually add anyway but it's something we could do over
time as we became much more familiar with the framework.

thnx,
Christoph

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] un-de-re-deprecation

2009-07-06 Thread Christoph Boget
http://us.php.net/manual/en/language.operators.type.php
The instanceof operator was introduced in PHP 5. Before this time
is_a() was used but is_a() has since been deprecated in favor of
instanceof. Note that as of PHP 5.3.0, is_a() is no longer deprecated.

http://us.php.net/manual/en/function.is-a.php
Changelog

Version Description
5.3.0   This function is no longer deprecated, and will therefore no
longer throw E_STRICT warnings.
5.0.0   This function became deprecated in favour of the instanceof
operator. Calling this function will result in an E_STRICT warning.

"Oh, never mind.  All that refactoring you did to take in to account
the deprecation of is_a(), well, sorry 'bout that.  We were a little
not right in the head when we originally made that decision.  You can
go ahead and change all that code back now if you like..."

Ok, so I'm curious, why was is_a() added back in when it was tossed
out on it's head in 5.0?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] fileinfo returning wrong mime type for Excel files

2009-07-29 Thread Christoph Boget
Consider the following:

$finfo = finfo_open( FILEINFO_MIME, '/usr/share/file/magic' );
if( $finfo )
{
  $mimeType = finfo_file( $finfo, '/path/to/my/excel.xls' );
  finfo_close($finfo);
}
echo $mimeType;

When I run the above, it echoes out "application/msword".  Why?  I
understand that both excel and word are part of the office suite but
why isn't it returning "application/excel" as it should?  As far as I
can tell, we're using the most up to date version of fileinfo for PHP
5.2.5.  Is there something else I'm missing?  Or doing wrong?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] fileinfo returning wrong mime type for Excel files

2009-07-30 Thread Christoph Boget
> > /usr/share/file/magic
> /usr/share/file/magic has lots of rules to know its type and its just
> matching it.

I know it has a lot of rules.  Grepping it for excel shows that there
are rules in it for those types of files as well.

> Maybe your file is quite strange . have you tried with other xls files?

Yes, I have; the result is the same for all.

> what does  "file /path/to/my/excel.xls"  say

$ file excel.xls
excel.xls: Microsoft Office Document

Interestingly...

$ file word.doc
word.doc: Microsoft Office Document

So apparently, to the file command, there is no distinction.  That
seems both odd and wrong to me.  But not nearly as wrong as fileinfo
reporting "application/msword" as the mime type of an excel document.

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] fileinfo returning wrong mime type for Excel files

2009-07-30 Thread Christoph Boget
> Have you tried using 'file -i' from the command line: after all you are 
> looking
> for a MIME type with your fileinfo...
> Having said that, with file -i on my system, Word documents are
> 'application/msword' and Excel files are 'application/octet-stream'

$ file -i excel.xls
excel.xls: application/msword

The xls file I am using was generated with Excel (of Office 2007) for
the Mac.  So either you have a different magic file (assuming that's
what the file command uses) than I do or different versions of excel
contain different information.

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] fileinfo returning wrong mime type for Excel files

2009-07-30 Thread Christoph Boget
>> Having said that, with file -i on my system, Word documents are
>> 'application/msword' and Excel files are 'application/octet-stream'
> Fedora11 (2.6.29.6-213.fc11.i586)
> $ file excel.xls
> excel.xls: CDF V2 Document, Little Endian, Os: Windows, Version 5.1, Code
> page: 1252, Author: ??, Last Saved By: ELAN, Name of
> Creating Application: Microsoft Excel, Last Printed: Sun Nov  6 18:04:20
> 2005, Create Time/Date: Tue Nov  1 02:56:47 2005, Security: 0

Red Hat 4.1.2-14

$ file excel.xls
excel.xls: Microsoft Office Document

I'm not getting all that extra information.

> $ file -i excel.xls
> excel.xls: application/vnd.ms-excel; charset=binary

$file -i excel.xls
excel.xls: application/msword

> I wonder if the problem lies with the documents themselves. Last May, I
> posted a msg here about how FileInfo was reporting back "application/msword
> application/msword" for some (but not all) Word docs. I never received a
> reply about it but came up with a hack to split on the space, if present.

I saw that post and that is something we are getting occasionally as
well.  And it may perhaps be an issue with the documents themselves.
As I stated in a post I just made, the excel document I'm looking at
was created using Office 2007 for the Mac.

thnx,
Christoph

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] fileinfo returning wrong mime type for Excel files

2009-07-30 Thread Christoph Boget
> The xls file I am using was generated with Excel (of Office 2007) for
> the Mac.  So either you have a different magic file (assuming that's
> what the file command uses) than I do or different versions of excel
> contain different information.

I just tried using an excel spreadsheet saved using Office 2003 on XP
and received the same output: application/msword.

thnx,
Christoph

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Generic decorators and type hinting

2009-09-02 Thread Christoph Boget
> I have a possibly-evil idea that gets around type-hinting by
> dynamically declaring decorator classes as children of the real
> classes that need to be timed. You end up with as many "decorators" as
> you have classes that need to be timed, but if this is for dev/QA
> purposes only, that might not be a problem.

You don't even need to do that; it'd generate way too much redundant
code.  Instead, just use interfaces.  The only real downside is that
all the classes you want to decorate would need to implement them and
that would cause a wee bit of ugliness in the code/class declaration.
But if you are fine with that, it's a perfect solution, particularly
since you can type hint interfaces.

interface iDecorator {}

class Thing implements iDecorator {}

class Timer
{
  public static function time( iDecorator $obj ) {}
}

$obj = new Thing();
Timer::time( $obj ); // $obj becomes a Timer obj with $obj inside it
$obj->thingMethod(); // Timer passes call to Timer->obj

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] stdout as input

2009-09-24 Thread Christoph Boget
I've read the section in the docs about i/o streams and other related
sections I was able to find but couldn't figure out how to do what I
need.  From the command line, I'm trying to pipe stdout in to my php
script which should then see it as input.  A simplistic example would
be:

echo bob | myScript.php

In myScript.php, I'm doing:

  $handle = popen( 'php://stdin', 'r' );
  echo var_export( $handle, TRUE ) . "\n\n";

I've also tried php://stdout and php://input.  I also tried eschewing
the php:// pseudo protocol and popen altogether and going with the
STDIN and STDOUT constants.  None of that worked.  Is there a way I
can pipe/redirect output from a command line uhh, command as input to
my script?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] stdout as input

2009-09-24 Thread Christoph Boget
> Isn't it simpler with
> http://www.php.net/manual/en/function.shell-exec.php
> ?

Perhaps.  But the command to execute would be relatively arbitrary.
What I'm trying to do is set up a script that will filter the results
of a grep.  But what I'm grepping and where I'm starting from would
change.  I suppose I could pass those arguments to my script and
access it using argv but I'm actually kind of curious how (if) I can
access output which has been piped (or redirected) to my script.

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] stdout as input

2009-09-24 Thread Christoph Boget
> Exactly.  And if you just want redirected data you can try:
> $data = file_get_contents("php://stdin");
> --or--
> For an array of lines:
> $lines = file("php://stdin");

This is exactly what I was looking for.  Thanks Shawn and Ben!

thnx,
Christoph

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Problem with XPath query

2009-12-14 Thread Christoph Boget
Given the following XML:


  

  

  


I'm using the following query:

$oXPath->query( '//DisplayRef/paramet...@alias="widgetType and
@value="system"]' );

and I'm getting the following error:

Warning: DOMXPath::query() [function.DOMXPath-query]: Invalid predicate

If I remove this part of the query

[...@alias="widgetType and @value="system"]

the error goes away.

As far as I can tell from googling around, the query is valid.  If
that's the case, I don't understand what's causing the error.
Could someone explain to me what I'm doing wrong?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problem with XPath query

2009-12-14 Thread Christoph Boget
> You are missing a quote after widgetType:

Yeah, I realized that about 2 minutes after I sent the message.  Man,
I'm dumb. :p  I was banging my head against the wall for a while
because of that.  I guess when you bring your stupidity public, you'll
find the solution yourself that much quicker. ;)

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] DirectoryIterator

2010-01-26 Thread Christoph Boget
I've looked through the docs but was unable to find out if this is possible;
I hope it is.  Is there a way that you get the size/length of the collection
to be iterated (e.g. the total number of files) without having to iterate
through at least once?

thnx,
Christoph


Re: [PHP] DirectoryIterator

2010-01-26 Thread Christoph Boget
>
> def not on DirectorIterator afaik, and furthermore, i dont think thats
> supported at the shell / filesystem level even.


Well if the Iterator has the whole of the collection in order to be able to
iterate over it, I would think that it should be able to return the size of
that collection... :(

thnx,
Christoph


Re: [PHP] DirectoryIterator

2010-01-26 Thread Christoph Boget
>
> right but the collection is built during iteration.
>

So you're saying that if I add a file to the directory between the time I
instantiate the DirectoryIterator and the time I'm finished iterating
through, that file could be picked up?  Or is the instance only going to
contain a list of files in that directory at the time the object was
constructed?

thnx,
Christoph


Re: [PHP] DirectoryIterator

2010-01-26 Thread Christoph Boget
I executed the following test script several times.  Each time, in a
separate terminal window, I ran "touch bob.txt" after the script started
echoing out.  After the script completed, I deleted bob.txt.  During each
execution, not once did bob.txt show up in the output.  This makes me
believe that the file collection that DirectoryIterator is going to work
with is set at instantiation.  If that's the case, it makes little sense to
me that you are unable to get the size of that collection from the
DirectoryInterator object.

getFilename() . '';
flush();
sleep( 1 );
  }
?>

thnx,
Christoph


[PHP] Extending Exception

2010-07-21 Thread Christoph Boget
Ok, so taking the sample code that is on the page

http://us3.php.net/manual/en/language.exceptions.extending.php

Literally, just cutting and pasting the code.  When I try to

throw new Exception( 'My Message' );

PHP spits out the following fatal error:

Fatal error: Wrong parameters for Exception([string $exception [, long $code ]])

and the line number it dies on is the line in the
MyException::__construct() where it is calling the parent's
constructor.  So what's going on?  Is the documentation wrong?  Is
this a bug?  Am I doing something wrong?

I'm using PHP 5.2.9.

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] json_encode() behavior and the browser

2010-09-01 Thread Christoph Boget
I'm curious if the behavior of json_encode() is influenced by the
browser at all.  I have a page that returns search results.  If I
access the page and perform a search using Chrome, the following error
shows up in the log:

PHP Warning:  json_encode() [function.json-encode]: Invalid UTF-8
sequence in argument in [PAGE] on line [LINE]

If I access the page and perform a search, the exact same search using
the exact same parameters, using Firefox then I get the expected
results.  When I var_dump() the return value of json_encode(), I see
that it is a null in the case where I accessed using chrome but the
expected string in the case where I accessed using firefox.  In both
cases, the input array is identical.

Given the identical input and different output, the only thing I can
figure is that the headers sent to the server as part of the request
figure in to how json_encode() behaves.  Is that the case?  Or am I
barking up the wrong tree?

To be clear, I'm not talking about how the browser ultimately handles
the json encoded data.  I know there can be issues with that.  I'm
talking about the process before the data is even shipped to the
browser -- about how json_encode() behaves when executed as part of
the PHP script.

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: json_encode() behavior and the browser

2010-09-01 Thread Christoph Boget
> It can have something to do with your browser codification (UTF8,
> ISO-8859-???).

But why would that be the case?  Is json_encode() actually encoding
the string differently in each case?  And would it encode it
differently if I wrote a script to take the same input and ran it from
the command line?

Is there a way I can get around this on the back end?  Make it so that
it'll behave the same in all cases?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: json_encode() behavior and the browser

2010-09-01 Thread Christoph Boget
> You should set the charset of your page by meta tag in its head.

Do you have a source of reference to which you point me?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: json_encode() behavior and the browser

2010-09-01 Thread Christoph Boget
> http://www.w3.org/TR/html4/charset.html
> I hope it can help you.
> PS: json_decode works only in utf8.

I understand charsets.  I understand the difference between the
charsets.  What I don't understand is how json_encode() is taking the
*exact same input* and behaving differently (breaking in one case,
working in another) depending on the browser being used.  And taking
your statement that json_encode() works only in utf-8 as a given, how
can I guard against the different behaviors on the backend, where
json_encode() is getting executed.  Should I do some kind of header
sniffing prior to every call to json_encode() and massage the data
accordingly depending on what I find?  That seems somewhat excessive.
But based on what you are saying and based on what I'm witnessing, it
seems like there is no other way around that.

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: json_encode() behavior and the browser

2010-09-01 Thread Christoph Boget
> Sorry about the error:
> In this case, you must set IT via meta tag to avoid it.

Ok, let's try this using a different approach.  Consider the following
pseudo-code:



Why does the charset of the browser matter one whit to the value of
either $row['name'] or $row['date'] such that it would break
json_encode() in one case and not the other.  Is it that PHP is taking
the string which is returned as part of the result set and encoding it
to match the charset passed in from the browser?

thnx,
Christoph

* Disclaimer : the actual code (and data repository) I am using is
slightly different from the above but is similar enough so that it's a
valid representation

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variable Question

2012-04-19 Thread Christoph Boget
> I am trying to use this while look to assign them to variables:
> $word_1
> $word_2
> $word_3
> ...
> $word_25

This should work for you:

http://us3.php.net/manual/en/function.extract.php

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] ZendCodeAnalyzer oddity

2012-10-31 Thread Christoph Boget

Consider the following code:

';
  }
}

bob::factory();
$var  =  'bob';
$var::factory();
?>

When I run this, "In Factory!" is displayed twice, as I would expect.  
So by all accounts, there's nothing wrong with the code.  However, when 
I run that file through ZendCodeAnalyzer, I get the following error:


(line 11): Zend Engine message: parse error
[Zend Code Analyzer] Aborted.

Line 11 is this:

$var::factory();

So why is ZendCodeAnalyzer reporting that as a parse error?  Shouldn't 
it behave as PHP does and play nice with it?


I'm running PHP 5.3.15, Zend Code Analyzer 1.2.2

thnx,
Christoph


[PHP] Issues with simplexml_load_string()

2011-10-06 Thread Christoph Boget
It seems like when dealing with nodes which have CDATA, I cannot get
access to both the attributes of that node and the CDATA of that node
with the same simplexml_load_string() call.  Consider the following:

$previewString =
'';

When passing LIBXML_NOCDATA:

echo '' . print_r( json_decode( json_encode(
(array)simplexml_load_string( $previewString, 'SimpleXMLElement',
LIBXML_NOCDATA | LIBXML_NOBLANKS )), 1 ), TRUE ) . '';

yields the following output :

Array
(
[message] => lkjlkjklj
[buttons] => Array
(
[button] => This is my free form text
)
)

So I get the CDATA but I don't get the "name" attribute for the button.

When not using LIBXML_NOCDATA:

echo '' . print_r( json_decode( json_encode(
(array)simplexml_load_string( $previewString, 'SimpleXMLElement',
LIBXML_NOBLANKS )), 1 ), TRUE ) . '';

yields the following output :

Array
(
[message] => Array
(
)
[buttons] => Array
(
[button] => Array
(
[@attributes] => Array
(
[name] => Add Me
)
)
)
)

I get the attributes but not the CDATA.  Looking at the doc page for
simplexml_load_string()
(http://us.php.net/manual/en/function.simplexml-load-string.php and
http://us.php.net/manual/en/libxml.constants.php), I don't see a way
to get access to both.  Am I missing something?  Or is this really not
possible?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Issues with simplexml_load_string()

2011-10-06 Thread Christoph Boget
It seems like when dealing with nodes which have CDATA, I cannot get
access to both the attributes of that node and the CDATA of that node
with the same simplexml_load_string() call.  Consider the following:

$previewString =
'';

When passing LIBXML_NOCDATA:

echo '' . print_r( json_decode( json_encode(
(array)simplexml_load_string( $previewString, 'SimpleXMLElement',
LIBXML_NOCDATA | LIBXML_NOBLANKS )), 1 ), TRUE ) . '';

yields the following output :

Array
(
   [message] => lkjlkjklj
   [buttons] => Array
   (
   [button] => This is my free form text
   )
)

So I get the CDATA but I don't get the "name" attribute for the button.

When not using LIBXML_NOCDATA:

echo '' . print_r( json_decode(
json_encode((array)simplexml_load_string( $previewString,
'SimpleXMLElement', LIBXML_NOBLANKS )), 1 ), TRUE ) . '';

yields the following output :

Array
(
   [message] => Array
   (
   )
   [buttons] => Array
   (
   [button] => Array
   (
   [@attributes] => Array
   (
   [name] => Add Me
   )
   )
   )
)

I get the attributes but not the CDATA.  Looking at the doc page for
simplexml_load_string()
(http://us.php.net/manual/en/function.simplexml-load-string.php and
http://us.php.net/manual/en/libxml.constants.php), I don't see a way
to get access to both.  Am I missing something?  Or is this really not
possible?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Issues with simplexml_load_string()

2011-10-07 Thread Christoph Boget
> http://us.php.net/manual/en/function.simplexml-load-string.php#80855 maybe?

Thanks for that.  I guess I should have scrolled a little further
down.  It's so crazy that it works that way.  Unless you export the
actual element (and not it's ancestors), you don't see the data at
all.

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Case insensitive ksort

2007-09-18 Thread Christoph Boget
I looked in the docs but didn't see anything regarding case
insensitivity and I fear the functionality doesn't exist.  I'm just
hoping I'm looking in the wrong place.

Is there a way to get ksort to work without regard to case?  When I
sort an array using ksort, all the upper case keys end up at the top
(sorted) and all the lower case keys end up at the bottom (sorted).
Ideally, I'd like to see all the keys sorted (and intermixed)
regardless of case.  Am I going to have to do this manually?  Or is
there an internal php command that will do it for me?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Job openings in Maryland

2007-09-18 Thread Christoph Boget
My company has the following job openings available:

Join in the Adventure.

Yakabod, a web software and services company, is located in a beautifully
restored facility in Frederick, Maryland's historic district. We've
experienced steady growth since starting in 2001. We've set our hearts on
building a great company. Now we're looking for some great people to help
fuel our growth. We need a skilled Software Test Engineer to join our
Application Factory team.

We'll expect you to have a combination of solid in-depth knowledge of QA,
QA's goals, working with QA and non-QA groups, and extensive background in
solid test coverage. You'll be responsible for providing Quality Assurance
for the Yakabod KnowledgeWork application. This will include the creation of
test suites and test harness for front and backend testing, API testing,
automating UI test cases, defining test plans and test specifications,
designing tools for automated performance testing, execution of test cases,
and reporting product failures. You'll work with development teams to ensure
that a product is testable, that it is adequately unit tested, and that it
can be automated even further in the test harness. You'll review design
documents for adequate testing hooks, and implement mock objects and servers
to help developers with their unit testing and to allow for testing of
components individually. Following project milestones, you'll design,
implement, document, and/or execute tests; evaluate and communicate results;
develop API tests; and investigate product features (including ad hoc
testing). You'll also work closely with developers in defect resolution and
assist troubleshooting issues.

You can communicate clearly and effectively. You will also be responsible
for setting up the processes required to promote the overall quality of the
product. You have the ability to influence, lead, manage and help build QA
with excellence, in a fun and fast-paced dynamic team and corporate
environment.

Software Test Engineer

Minimum skills:
* 5-6 years of overall IT experience
* 3+ years software quality assurance testing
* 3+ years experience with automated test tools and load testing packages
(especially any PHP related testing tools i.e. PHPUnit)
* 2+ years creating and writing test plans and test scripts
* 2+ years web based testing
* Experience with XML and web services testing
* Experience with SQL and data retrieval from a relational database (i.e.,
MySql, Oracle)
* Strong UNIX background especially Linux
* Ability to work against extremely tight deadlines
* Experience in HTML, Java Script, DHTML

Preferred skills:
* Bachelors degree with emphasis on CS, CE and EE majors
* Familiarity with quality methodologies such as: CMM, ISO or IEEE.
* Familiarity with the Agile Development Framework
* Experience in PHP, PERL and shell scripting is a strong plus
* Strong understanding of all aspects of the QA role and all areas of
application testing
* Detailed understanding of the entire development cycle
* Experience with defect tracking systems and other software life cycle
management tools (Bugzilla)
* Knowledge of and ability to rapidly learn third party development/QA tools
* Capacity for attention to details
* Strong organizational and communication skills



Web Application Developers

We're still small, so you'll do a bit of everything –from integrating and
supporting critical customer applications to creating new components in our
core software products. Specifically, you can do many of the following with
excellence:

• Lead, manage, and/or architect knowledge-based dynamic web applications
• Develop software using PHP, MySQL, JavaScript, HTML, XML, AJAX and other
web application environments (experience with J2EE or MS environments will
be considered if you have demonstrated strong lifecycle development and
problem solving skills).
• Capture requirements, and then create use cases, specs, object-oriented
design, user interfaces, and data models
• Execute disciplined development practices over a full-lifecycle
• Deploy, support, and maintain customer applications, including
networks,Linux servers, development tools, and custom applications

We'll expect you to reliably "get things done" – you're a self-motivated,
entrepreneurial, problem solver who desires to be part of a team that builds
software that "works the way it ought to". You thrive as part of a team
that's undertaking a bold adventure together. Most important, you resonate
with our core values and culture. Experience in an early stage tech firm is
desirable, but not required. An active TS/SCI clearance with polygraph is
desirable, but not required. If you don't have one, you must be willing to
be submitted for clearance processing.

We're not looking for "bodies", just a few select impact players. We've set
pay and benefits accordingly, including participation in our generous stock
options plan and plenty of great coffee.

Interested?

Send your resume to [EMAIL PROTECTED]


Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-10-09 Thread Christoph Boget
>
> Maybe next time you'll have a challenge for me ;) And don't whine about
> how I achieved what I did.


Brilliant!  I never would have thought of that. ;)

thnx,
Christoph


[PHP] json_encode/json_decode, take 2

2007-10-19 Thread Christoph Boget
The string used below in "$myArrEncoded" is generated in javascript, after
creating the structure and spitting out:

var JSONVar = javascriptVar.toSource();

I can eval JSONVar and work with it as I would be working with the original
javascriptVar so I know the transition back and forth from a structure to a
string isn't causing problems.  The problem is when I try to work with the
string in PHP.

Here is my code:

';
  echo '$myArr encoded: ' . $myArrEncoded . '';
  try {
echo '$myArr decoded: ' . print_r( json_decode( $myArrEncoded, TRUE
), TRUE ) . '';
  } catch( Exception $e ) {
echo 'Error: ' . var_dump( $e );
  }

?>

When I run it, I get the following output:



string(587) "({Salary:{'50-70K':{filterType:"range",
fieldName:"SALARY", fieldValueLabel:"50-70K", lowerValue:"50",
upperValue:"70", inclusive:"BOTH"}},
Position:{Developer:{filterType:"single", fieldName:"POSITION",
fieldValueLabel:"Developer", fieldValue:"Developer",
constraint:"equals"}, SysAdmin:{filterType:"single",
fieldName:"POSITION", fieldValueLabel:"System Admin",
fieldValue:"SysAdmin", constraint:"equals"}}, 'Required Action':{'2 -
GenScreen':{filterType:"single", fieldName:"REQUIRED_ACTION",
fieldValueLabel:"General Phone Screen", fieldValue:"2 - GenScreen",
constraint:"equals"}}})"

$myArr encoded: ({Salary:{'50-70K':{filterType:"range",
fieldName:"SALARY", fieldValueLabel:"50-70K", lowerValue:"50",
upperValue:"70", inclusive:"BOTH"}},
Position:{Developer:{filterType:"single", fieldName:"POSITION",
fieldValueLabel:"Developer", fieldValue:"Developer",
constraint:"equals"}, SysAdmin:{filterType:"single",
fieldName:"POSITION", fieldValueLabel:"System Admin",
fieldValue:"SysAdmin", constraint:"equals"}}, 'Required Action':{'2 -
GenScreen':{filterType:"single", fieldName:"REQUIRED_ACTION",
fieldValueLabel:"General Phone Screen", fieldValue:"2 - GenScreen",
constraint:"equals"}}})

$myArr decoded: ({Salary:{'50-70K':{filterType:"range",
fieldName:"SALARY", fieldValueLabel:"50-70K", lowerValue:"50",
upperValue:"70", inclusive:"BOTH"}},
Position:{Developer:{filterType:"single", fieldName:"POSITION",
fieldValueLabel:"Developer", fieldValue:"Developer",
constraint:"equals"}, SysAdmin:{filterType:"single",
fieldName:"POSITION", fieldValueLabel:"System Admin",
fieldValue:"SysAdmin", constraint:"equals"}}, 'Required Action':{'2 -
GenScreen':{filterType:"single", fieldName:"REQUIRED_ACTION",
fieldValueLabel:"General Phone Screen", fieldValue:"2 - GenScreen",
constraint:"equals"}}})



Why isn't json_decode() converting the string to an array?  Is there
something extra in there that json_decode() can't deal with?  I can work
with it fine in javascript... :(

thnx,
Christoph


[PHP] Re: json_encode/json_decode

2007-10-19 Thread Christoph Boget
Please disregard.  Sometimes I weep at my own stupidity... :p

thnx,
Christoph

On 10/19/07, Christoph Boget <[EMAIL PROTECTED]> wrote:
>
> Please take a look at the following code and tell me what I'm doing wrong
> here.  I'm just not understanding why this isn't working:


[PHP] json_encode/json_decode

2007-10-19 Thread Christoph Boget
Please take a look at the following code and tell me what I'm doing wrong
here.  I'm just not understanding why this isn't working:

 array( 'Key 1 1' => array( array( 'Key 1 1 1'
=> 'Value' ),
array( 'Key 1 1 2'
=> 'Value' )),
'Key 1 2' => array( array( 'Key 1 2 1'
=> 'Value' ),
array( 'Key 1 2 2'
=> 'Value' ))),
  'Key 2' => array( 'Key 2 1' => array( array( 'Key 2 1 1'
=> 'Value' ),
array( 'Key 2 1 2'
=> 'Value' )),
'Key 2 2' => array( array( 'Key 2 2 1'
=> 'Value' ),
array( 'Key 2 2 2'
=> 'Value' ;
  echo '$myArr: ' . print_r( $myArr, TRUE ) . '';
  $myArrEncoded = json_encode( $myArr );
  echo var_dump( $myArrEncoded ) . '';
  echo '$myArr encoded: ' . $myArrEncoded . '';
  try {
echo '$myArr decoded: ' . json_decode( $myArrEncoded ) .
'';  // this is line 16
  } catch( Exception $e ) {
echo 'Error: ' . var_dump( $e );
  }

?>


When I run the above, I get the following.  Please note that line 16 is in a
TRY block yet it still gives the error seen below:

$myArr:

Array
(
[Key 1] => Array
(
[Key 1 1] => Array
(
[0] => Array
(
[Key 1 1 1] => Value
)

[1] => Array
(
[Key 1 1 2] => Value
)

)

[Key 1 2] => Array
(
[0] => Array
(
[Key 1 2 1] => Value
)

[1] => Array
(
[Key 1 2 2] => Value
)

)

)

[Key 2] => Array
(
[Key 2 1] => Array
(
[0] => Array
(
[Key 2 1 1] => Value
)

[1] => Array
(
[Key 2 1 2] => Value
)

)

[Key 2 2] => Array
(
[0] => Array
(
[Key 2 2 1] => Value
)

[1] => Array
(
[Key 2 2 2] => Value
)

)

)

)


string(245) "{"Key 1":{"Key 1 1":[{"Key 1 1 1":"Value"},{"Key 1 1
2":"Value"}],"Key 1 2":[{"Key 1 2 1":"Value"},{"Key 1 2 2":"Value"}]},"Key
2":{"Key 2 1":[{"Key 2 1 1":"Value"},{"Key 2 1 2":"Value"}],"Key 2 2":[{"Key
2 2 1":"Value"},{"Key 2 2 2":"Value"}]}}"

$myArr encoded: {"Key 1":{"Key 1 1":[{"Key 1 1 1":"Value"},{"Key 1 1
2":"Value"}],"Key 1 2":[{"Key 1 2 1":"Value"},{"Key 1 2 2":"Value"}]},"Key
2":{"Key 2 1":[{"Key 2 1 1":"Value"},{"Key 2 1 2":"Value"}],"Key 2 2":[{"Key
2 2 1":"Value"},{"Key 2 2 2":"Value"}]}}


*Catchable fatal error*: Object of class stdClass could not be converted to
string in */path/to/my/file.php* on line *16


*Now, if I change it so that I pass the second parameter as TRUE for
json_decode (ie, change my code as follows:

echo '$myArr decoded: ' . json_decode( $myArrEncoded, TRUE ) .
'';  // this is line 16

), then here is what I get:

$myArr:

Array
(
[Key 1] => Array
(
[Key 1 1] => Array
(
[0] => Array
(
[Key 1 1 1] => Value
)

[1] => Array
(
[Key 1 1 2] => Value
)

)

[Key 1 2] => Array
(
[0] => Array
(
[Key 1 2 1] => Value
)

[1] => Array
(
[Key 1 2 2] => Value
)

)

)

[Key 2] => Array
(
[Key 2 1] => Array
(
[0] => Array
(
[Key 2 1 1] => Value
)

[1] => Array
(
[Key 2 1 2] => Value
)

)

[Key 2 2] => Array
(
[0] => Array
(
[Key 2 2 1] => Value
)

[1] => Array
(
 

[PHP] Benchmarking check to see if array key is set

2007-11-06 Thread Christoph Boget
Consider the following test code:

';

  $startTime = microtime( TRUE );
  $foundCount = 0;
  for( $i = 0; $i <= 1; $i++ )
  {
$date = microtime( TRUE );
$key  = rand( $date, $date * rand( 1, 5000 ));
if( array key exists( $key, $myArray ))
{
  $foundCount++;

}
  }
  $endTime = microtime( TRUE );
  echo 'array key exists took [' . ( $endTime - $startTime ) . '] seconds;
found: [' . $foundCount . '] keys';

  $startTime = microtime( TRUE );
  $foundCount = 0;
  for( $i = 0; $i <= 1; $i++ )
  {
$date = microtime( TRUE );
$key  = rand( $date, $date * rand( 1, 5000 ));
if( isset( $myArray[$key] ))
{
  $foundCount++;

}
  }
  $endTime = microtime( TRUE );
  echo 'isset took [' . ( $endTime - $startTime ) . '] seconds; found: [' .
$foundCount . '] keys';

  $startTime = microtime( TRUE );
  $foundCount = 0;
  for( $i = 0; $i <= 1; $i++ )
  {
$date = microtime( TRUE );
$key  = rand( $date, $date * rand( 1, 5000 ));
if( $myArray[$key] )
{
  $foundCount++;

}
  }
  $endTime = microtime( TRUE );
  echo 'IF() took [' . ( $endTime - $startTime ) . '] seconds; found: [' .
$foundCount . '] keys';
?>

Running that I found that

if( isset( $myArray[$key] ))

is faster than

if( array key exists( $key, $myArray ))

is faster than

if( $myArray[$key] )

To be honest, I was surprised.  I would have thought that if( $myArray[$key]
) would have been the fastest way to check.  I'm wondering if those in the
know could explain why it's the slowest and also where the discrepancies
come from w/r/t the difference in the amount of time it takes to make each
check.

thnx,
Chris


[PHP] Jobs in Frederick, MD

2007-11-13 Thread Christoph Boget
My company has the following job openings available.  Be sure to check out
our recruiting video at https://www.yakabod.com/join.html?nav=4.  It's a
pretty fun watch. :)


Join in the Adventure.

Yakabod, a web software and services company, is located in a beautifully
restored facility in Frederick, Maryland's historic district. We've
experienced steady growth since starting in 2001. We've set our hearts on
building a great company. Now we're looking for some great people to help
fuel our growth. We need a skilled Software Test Engineer to join our
Application Factory team.

We'll expect you to have a combination of solid in-depth knowledge of QA,
QA's goals, working with QA and non-QA groups, and extensive background in
solid test coverage. You'll be responsible for providing Quality Assurance
for the Yakabod KnowledgeWork application. This will include the creation of
test suites and test harness for front and backend testing, API testing,
automating UI test cases, defining test plans and test specifications,
designing tools for automated performance testing, execution of test cases,
and reporting product failures. You'll work with development teams to ensure
that a product is testable, that it is adequately unit tested, and that it
can be automated even further in the test harness. You'll review design
documents for adequate testing hooks, and implement mock objects and servers
to help developers with their unit testing and to allow for testing of
components individually. Following project milestones, you'll design,
implement, document, and/or execute tests; evaluate and communicate results;
develop API tests; and investigate product features (including ad hoc
testing). You'll also work closely with developers in defect resolution and
assist troubleshooting issues.

You can communicate clearly and effectively. You will also be responsible
for setting up the processes required to promote the overall quality of the
product. You have the ability to influence, lead, manage and help build QA
with excellence, in a fun and fast-paced dynamic team and corporate
environment.

Software Test Engineer

Minimum skills:
* 5-6 years of overall IT experience
* 3+ years software quality assurance testing
* 3+ years experience with automated test tools and load testing packages
(especially any PHP related testing tools i.e. PHPUnit)
* 2+ years creating and writing test plans and test scripts
* 2+ years web based testing
* Experience with XML and web services testing
* Experience with SQL and data retrieval from a relational database ( i.e.,
MySql, Oracle)
* Strong UNIX background especially Linux
* Ability to work against extremely tight deadlines
* Experience in HTML, Java Script, DHTML

Preferred skills:
* Bachelors degree with emphasis on CS, CE and EE majors
* Familiarity with quality methodologies such as: CMM, ISO or IEEE.
* Familiarity with the Agile Development Framework
* Experience in PHP, PERL and shell scripting is a strong plus
* Strong understanding of all aspects of the QA role and all areas of
application testing
* Detailed understanding of the entire development cycle
* Experience with defect tracking systems and other software life cycle
management tools (Bugzilla)
* Knowledge of and ability to rapidly learn third party development/QA tools
* Capacity for attention to details
* Strong organizational and communication skills



Web Application Developers

We're still small, so you'll do a bit of everything –from integrating and
supporting critical customer applications to creating new components in our
core software products. Specifically, you can do many of the following with
excellence:

• Lead, manage, and/or architect knowledge-based dynamic web applications
• Develop software using PHP, MySQL, JavaScript, HTML, XML, AJAX and other
web application environments (experience with J2EE or MS environments will
be considered if you have demonstrated strong lifecycle development and
problem solving skills).
• Capture requirements, and then create use cases, specs, object-oriented
design, user interfaces, and data models
• Execute disciplined development practices over a full-lifecycle
• Deploy, support, and maintain customer applications, including
networks,Linux servers, development tools, and custom applications

We'll expect you to reliably "get things done" – you're a self-motivated,
entrepreneurial, problem solver who desires to be part of a team that builds
software that "works the way it ought to". You thrive as part of a team
that's undertaking a bold adventure together. Most important, you resonate
with our core values and culture. Experience in an early stage tech firm is
desirable, but not required. An active TS/SCI clearance with polygraph is
desirable, but not required. If you don't have one, you must be willing to
be submitted for clearance processing.

We're not looking for "bodies", just a few select impact players. We've set
pay and benefits accordingly, including participation in our gener

[PHP] sprintf() oddness

2007-12-01 Thread Christoph Boget
Why does

sprintf( '%.03f', 0.1525 )

return 0.152 while

sprintf( '%.03f', 0.1575 )

return 0.158?

The 4th significant digit in both cases is '5' but in the first case, it's
rounded down but in the second case it is rounded up.  Is sprintf() basing
it's decision on the value of the 3rd significant digit?  If so, why?
Shouldn't rounding decisions be based on subsequent digits and not preceding
ones?

I am using PHP 4.3.11

thnx,
Christoph


[PHP] Change case of HTML tags

2007-12-19 Thread Christoph Boget
I've been looking through the docs but haven't found an internal function
that does what I'm looking for.  Perhaps I missed it?  Or perhaps someone
can point me in the right direction?  I'm looking for a routine that will
convert tags to lower case.  For example, if I have


  
This is the Page Title
  
  
Here is the Page Text
  


I want to convert only the tags to lower case.  So  becomes  and
so on; I don't want anything else touched.  This may seem kind of silly but
I'm working with an XMLDocument object in javascript and when I serialize it
to string format, for some reason all the tags are made into uppercase.  I'm
taking the serialized string, posting it back to the server and using it on
the back end.  I figure that since I can make it so that the serialized
string is lower case on the front end, perhaps I can convert it on the back.

Any ideas/pointers?

thnx,
Christoph


[PHP] Change case of HTML tags

2007-12-19 Thread Christoph Boget
I've been looking through the docs but haven't found an internal function
that does what I'm looking for.  Perhaps I missed it?  Or perhaps someone
can point me in the right direction?  I'm looking for a routine that will
convert tags to lower case.  For example, if I have


  
This is the Page Title
  
  
Here is the Page Text
  


I want to convert only the tags to lower case.  So  becomes  and
so on; I don't want anything else touched.  This may seem kind of silly but
I'm working with an XMLDocument object in javascript and when I serialize it
to string format, for some reason all the tags are made into uppercase.  I'm
taking the serialized string, posting it back to the server and using it on
the back end.  I figure that since I can make it so that the serialized
string is lower case on the front end, perhaps I can convert it on the back.

Any ideas/pointers?

thnx,
Christoph


Re: [PHP] Which file called the function?

2007-12-20 Thread Christoph Boget
> I believe __FILE__ is resolved at compile time, not run-time which  
> means what you're seeing is expected behavior. I'm not sure how you'd  
> get the name of the file that a function call was made from.
> Could you explain why you need this information in your application,  
> and perhaps someone might offer an alternative solution?

I'm not saying it's not expected behavior.  In fact, that exactly what I
would expect based on what the docs say.  I'm just asking if there is
another way to get the script file name that's calling the function.

I need it primarily for debugging purposes.  I've got a single function
that's called by several files.  And instead of modifying all the files
calling the function to add logging, it would be nice to just modify the
function, adding logging only to it to also include what script called it.
 

I know I can get the information from debug_backtrace but I figured there
might be a better/easier way.

thnx,
Christoph


  

Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Which file called the function?

2007-12-20 Thread Christoph Boget
Let's say I have the following 3 files

global.php


one.php


two.php


In each case, what is echoed out for __FILE__ is global.php.  Apart from
analyzing the debug_backtrace array, is there any way that myFunc() would
display "one.php" and "two.php" respectively?

thnx,
Christoph


[PHP] Does a package like this exist

2008-01-04 Thread Christoph Boget
Not wanting to re-invent the wheel, I'm wondering if there is a package out
there that can read in an HTML file and allow you to manipulate and dissect
it much like you can in javascript?  For example, functionality similar to
(though, not necessarily the same as) getElementById(), .innerHTML, etc.

I need to write a conversion script that reorganizes the contents of a large
number of HTML files and I'm hoping that there is something out there that
might make this task a bit easier.  I've done some searching on Google but
didn't really find anything.  I'm hoping that someone might be able to point
me to something I might have missed.

thnx,
Christoph


[PHP] DOMDocument->getElementById() isn't working

2008-01-04 Thread Christoph Boget
Here is the input string I'm using:


  

  

  

  {display ref="BYOPPageMetaData" id="3"}

  


  

  {display ref="ResourceList" id="0"}

  

  

  



And here is the PHP stub I'm using:

  $oDOMDocument = new DOMDocument;
  $oDOMDocument->preserveWhiteSpace = false;
  $oDOMDocument->formatOutput = true;
  $oDOMDocument->validateOnParse = true;

  if( $oDOMDocument->loadHTML( $cleanedFile ))
  {
$aLayoutNodes = $oDOMDocument->getElementsByTagName("div");
if( 0 < count( $aLayoutNodes ))
{
  echo 'Found [' . count( $aLayoutNodes ) . '] nodes.' . "\n";
  foreach( $aLayoutNodes as $oLayoutNode )
  {
$sLayoutId = $oLayoutNode->getAttribute( 'id' );
echo 'Current Id: [' . $sLayoutId . ']' . "\n";

  }
}

$oCustomNode = $oDOMDocument->getElementById( "custom" );
echo 'Tag: ' . $oCustomNode->nodeValue . "\n";

  }


Getting the elements by tag name, while iterating through the list I see
that one of the nodes has an id of 'custom'.  However, when I try to get the
element directly using getElementById(), it doesn't return the node
properly.  Am I doing something wrong?

Also, as an aside, one thing that I found odd is that count( $aLayoutNodes )
shows as 1 even though more are found.  Huh?

thnx,
Christoph


Re: [PHP] Re: DOMDocument->getElementById() isn't working

2008-01-07 Thread Christoph Boget
>
> > that one of the nodes has an id of 'custom'.  However, when I try to get
> the
> > element directly using getElementById(), it doesn't return the node
> > properly.  Am I doing something wrong?
>
> A common problem. See here:
> http://wiki.flux-cms.org/display/BLOG/GetElementById+Pitfalls
>
> Probably easiest to use XPath. Otherwise you have to slightly modify
> your HTML...


Thanks for the link.  It was very informative.  I've switched to using XPath
and that seems to have solved my problems.  Thanks for the  help!

thnx,
Christoph


[PHP] Determine which are user defined keys?

2008-01-11 Thread Christoph Boget
Given the following array:

 'bob', "0" => 'briggs', 'whatever', 'whereever');
  echo '' . print_r( $myArr, TRUE ) . '';
?>

Array
(
 [joe] => bob
 [0] => briggs
 [1] => whatever
 [2] => whereever
)

"joe" and "0" are keys that I created whereas the key "1" and "2" are
keys assigned by PHP when the array was created.  When iterating
through an array, is there a way to determine which were generated by
PHP?  I can't rely on whether or not the key is an integer because
it's quite possible that such a key was user generated.  I've gone
through the docs and based on what I've read, I don't think something
like this is possible but I'm hoping that's not the case.

Any pointers?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Determine which are user defined keys?

2008-01-11 Thread Christoph Boget
> > "joe" and "0" are keys that I created whereas the key "1" and "2" are
> > keys assigned by PHP when the array was created.  When iterating
> > through an array, is there a way to determine which were generated by
> > PHP?  I can't rely on whether or not the key is an integer because
> > it's quite possible that such a key was user generated.  I've gone
> > through the docs and based on what I've read, I don't think something
> > like this is possible but I'm hoping that's not the case.
> > Any pointers?
> explain what your trying to achieve and why. because it seems like your
> 'requirement' is a result of tackling the problem from the wrong end.

array_merge() clobbers the value of a particular key if that key
exists in any of the arrays that appear later in the argument list for
that function.  If I want it so that I can merge arrays but make it so
that all the values are retained, I need to write a function myself.
So basically I end up with something that approximates:

function array_merge_retain( $arr1, $arr2 ) {
  $retval = array();

  foreach( $arr1 as $key => $val ) {
$retval[$key][] = $val;
  }

  foreach( $arr2 as $key => $val ) {
$retval[$key][] = $val;
  }
  return $retval;

}

(there would be a lot of other stuff going on, error checking and
such, but the above is just bare bones).

What that gives me is an array where the values for keys that appear
in both arrays are retained.  The above function is all well and fine,
I suppose, but when the keys were created by PHP, I don't really care
about retaining the key.  If the key was created by PHP, i'd just do
an array_push() instead of explicitly defining the key, as I am in the
above function.  That way, in the end, the merged array would contain
arrays for values for only those keys that were user defined.

Consider the following example:

$myArr1 = array( 'joe' => 'bob', "0" => 'briggs', 'whatever', 'whereever');
$myArr2 = array( 'joe' => 'that', "0" => 'other', 'this', 'there');

the values 'whatever' and 'this' both have a key of 1 while 'wherever'
and 'there' both have a key of 2.  When merged, I envision the new
array looking something like this:

Array
(
 [joe] => array( bob, that )
 [0] => array( briggs, other )
 [1] => whatever
 [2] => whereever
 [3] => other
 [4] => there
)

but my function above would create an array that looks like this:

Array
(
 [joe] => array( bob, that )
 [0] => array( briggs, other )
 [1] => array( whatever, this )
 [2] => array( whereever, there )
)

perhaps I am approaching this a$$backwards.  I just wanted to keep the
merged array in more or less the same form as the original arrays in
the sense that those values that didn't originally have a user defined
key are not grouped together like those that did originally have a
user defined key.

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] How can I do this -- method chaining

2008-01-29 Thread Christoph Boget
Constructors return the object, correct?  If so, how can I do this:

class Bob {
  private $blah;
  _construct( $blah ) {
$this->blah = $blah;
  }
  public getBlah() {
return $this->blah;
  }
}

echo Bob( 'Hello!' )->getBlah();

When I try that, I get the message "Undefined function Bob".  I've also tried

echo new Bob( 'Hello!' )->getBlah();
echo (new Bob( 'Hello!' ))->getBlah();

but PHP didn't like either of those at all.  Is it just not possible
what I'm trying to do?

I'm using PHP5.2.1

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How can I do this -- method chaining

2008-01-29 Thread Christoph Boget
> On Jan 29, 2008 2:37 PM, Paul Scott <[EMAIL PROTECTED]> wrote:
> > Looks like a repurpose of one of my posts:
> >
http://fsiu.uwc.ac.za/index.php?module=blog&action=viewsingle&postid=gen9Srv59Nme5_7092_1182404204
> actually, this is slightly different; here we are talking about being
> able to immediately invoke a method  off the call to the constructor,
> whereas in your post you chain calls after storing the instance in a
> variable in the call to the constructor.

Right, and that's what I was trying to avoid, if possible.

thnx,
Chris


  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Template system in PHP

2008-02-12 Thread Christoph Boget
> > eval() is my favorite templating engine.
> > http://php.net/eval
> Ditto on Eval()
> PHP is already a templating system. Why go the long way around?

eval()?  Man, you guys have some seriously large cajones. :p

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Template system in PHP

2008-02-12 Thread Christoph Boget
> I agree.  I usually add a little function like this to my PHP projects:
> function debug( $var )
> {
>   echo '';
>   print_r( $var );
>   echo '';
>
> }

As an aside, you can save lines when debugging by doing:

echo '' . print_r( $var, TRUE ) . '';

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Template system in PHP

2008-02-13 Thread Christoph Boget
> > As an aside, you can save lines when debugging by doing:
> > echo '' . print_r( $var, TRUE ) . '';
> OMG, thanks for that.  Lines are so expensive nowadays and all.

Sarcasm aside, when I'm debugging I like to be as concise as possible.

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Template system in PHP

2008-02-13 Thread Christoph Boget
>  > when I'm debugging I like to be as concise as possible.
> Concise? Really?

Fair enough.  Perhaps I should have said concise with my code, verbose
with my actual messages. :p

thnx,
Chris


  

Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Are these Truthful Proof about PHP ??

2008-02-27 Thread Christoph Boget
> http://msdn2.microsoft.com/en-us/library/aa479002.aspx
> I read an Article on the above Microsoft website stating the reason why to 
> Migrate from PHP to
> ASP.NET. So can you please justify this proofs from Microsoft and let 
> everybody knows if they are
> all TRUE and MEANIFUL atall or they are just cheap lies to backup their 
> product. Please advice?

Well, the first thing to consider is that they are comparing PHP4 to
ASP, completely ignoring PHP5 which came out 3.5 years ago...

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] reverse string without strrev();

2008-02-28 Thread Christoph Boget
>  >> should it not use curlies?
>  > No, they will be deprecated as of PHP6. (Square brackets used to be, but
>  > have been undeprecated and are back in favour!)
>  cheers for the heads up on curlies Mike :)

Where can I read more information about this?

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] best practices in error handling in PHP

2008-03-12 Thread Christoph Boget
>  I want to know what is the best solution for handling errors. After reading 
> some
> documents dealing with the subject, i have three options:
>  * Using a class for error handling
>  * Using PEAR error object
>  * Using try and catch exceptions
>  The error handling i want to implement will be done in a big application 
> that was
> developed from the beginning without any concern about error handling.

It seems to me that 1 and 3 aren't necessarily mutually exclusive.  I
believe that you can use your own error classes in php's try/catch
functionality.  As for PEAR's error object, unless you are using PEAR
elsewhere in your app I'm not sure it would be worthwhile to just use
this very small piece.

This is all just IMO.

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Possible using XPath?

2008-03-27 Thread Christoph Boget
Let's say I have the following structure:

























By using the following XPath query

//[EMAIL PROTECTED]"gc3"]/child

I can get the child nodes of "gc1".  But what I'd really like to get
is the sub branch/path going back to the root.  So instead of just
returning the two nodes




I'd like to be able to return the sub branch/path


  

  
  

  


Is that possible?  Or is this something I'd have to do programatically
using the nodes returned by the XPath query?  Basically, I'm just
trying to get a fragment of the larger xml document...

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Possible using XPath?

2008-03-27 Thread Christoph Boget
>  >  Is that possible?  Or is this something I'd have to do programatically
>  >  using the nodes returned by the XPath query?  Basically, I'm just
>  >  trying to get a fragment of the larger xml document...
>  //[EMAIL PROTECTED]'gc3']/child/ancestor-or-self::*

Thanks for the response.  However, I must be doing something wrong
here.  The test script below isn't doing what I'm expecting:

  $xml = 'Great Grand Child
1Great Grand Child 2Great Grand Child 3Great Grand Child 4Great Grand Child
5Great Grand Child 6Great Grand Child 7Great Grand Child 8';

  $doc = new DOMDocument('1.0', 'UTF-8');
  $doc->loadXML( $xml );

  $xpath = new DOMXPath($doc);
  $nodeList = $xpath->query("//[EMAIL 
PROTECTED]'gc3']/child/ancestor-or-self::*");

  echo 'Got list list of [' . $nodeList->length . '] nodes:';
  for ($i = 0; $i < $nodeList->length; $i++) {
  echo $nodeList->item($i)->nodeValue . "\n";
  }

When I run the XPath query through XMLSpy, the correct nodes are
returning.  However, when I run it through DOMXPath->query() (or
evaluate() for that matter), it doesn't seem to be returning the
correct nodes.

What's going wrong?

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Having problems with XMLDocument

2008-03-27 Thread Christoph Boget
What is wrong with the following code?  It's throwing a DOMException
when I try to set the id attribute for the $lvl1Node but I can't see
why...

  $doc = new DOMDocument('1.0', 'UTF-8');
  $root = $doc->appendChild( $doc->createElement( 'root' ));
  for( $a = 0; $a <= 3; $a++ )
  {
$lvl_1_id = 'level_1_' . $a;

$lvl1Node = $root->appendChild( $doc->createElement( 'child', $lvl_1_id ));
$lvl1Node->setIdAttribute( 'id', $lvl_1_id );

  }

  for( $b = 0; $b <= 3; $b++ )
  {
$lvl_1_id = 'level_1_' . $b;
$lvl_2_id = 'level_2_' . $b;

$oElTmp = $doc->getElementById( $lvl_1_id );
if( $oElTmp )
{
  $lvl2Node = $oElTmp->appendChild( $doc->createElement( 'child',
$lvl_2_id ));
  $lvl2Node->setIdAttribute( 'id', $lvl_2_id );

}
else
{
  echo 'Could not find element with id [' . $lvl_1_id . ']';

}
  }

  echo '' . htmlentities( $doc->saveXML()) . '';


Any pointers would be greatly appreciated.

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] April Fools Easter Egg

2008-04-01 Thread Christoph Boget
>  > You got me.
>  Wobbly PHP logo on mine (PHP-5.2.5 debian)

That's all I see for PHP-5.2.1.  Should there be something more?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] April Fools Easter Egg

2008-04-01 Thread Christoph Boget
>  >>  Wobbly PHP logo on mine (PHP-5.2.5 debian)
>  > That's all I see for PHP-5.2.1.  Should there be something more?
>  Probably not, but check the source. :-)

I checked the source.  I didn't notice anything unusual...

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Problem with DOMElement/Node

2008-04-09 Thread Christoph Boget
Could someone explain to me what I'm doing wrong?

I'm trying to get an element from one DOMDocument and append it to a
different DOMDocument.  The (simplified) output of saveXML() from the
first DOMDocument is as follows:

 12

Here is a snippet of code:

createElement( 'menu' );
$oRootNode->setAttribute( 'id', 'root' );
$oRootNode->setIdAttribute( 'id', TRUE );

$oRootNode->setAttribute( 'style', $sStyle );
$oRootNode->setAttribute( 'width', $iWidth );
$oRootNode->setAttribute( 'target', $sTarget );
$oRootNode->setAttribute( 'indent', $iIndent );

$oXmlDocument->appendChild( $oRootNode );

$oNewChildEl = $oFirstDoc->getElementById( 'root' );
$oRootNode->appendChild( $oNewChildEl );
?>

I'm printing out what $oNewChildEl is to see if it's not returning the
proper element, using

echo '[' . $oNewChildEl->tagName . ']' . var_dump( $oNewChildEl );

and I'm seeing:

object(DOMElement)#1055 (0) { } [BranchRoot]

so it does look like it's returning the proper DOMElement.  But even
so, I'm getting a fatal error when $oRootNode is trying to
appendChild().  Specifically, the error I'm getting is

Fatal error: Uncaught exception 'DOMException' with message 'Wrong
Document Error'

What's going on?  It doesn't seem like I'm doing anything wrong but
something is causing the problem and I apparently do not understand
exactly what.

Could anyone lend any insight as to what's going on?  And what I might
do to get what I need done?

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Problem with DOMElement/Node

2008-04-09 Thread Christoph Boget
>  DOM Nodes are specific to the document in which they were created, so
>  you can't just append a node from one document into another document.
>  The importNode function does what you want.
>  http://us2.php.net/manual/en/function.dom-domdocument-importnode.php

Interesting.  Why is that, out of curiosity?

Thanks for the pointer!  That's exactly what I needed. :)

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Function not in the documentation

2008-05-20 Thread Christoph Boget
I ran across a PHP function, strip_illegal_chars(), but can't seem to
find anything about it in the documentation.  Does anyone know
precisely what it does?  Or where I can find actual documentation for
that function?

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Method chaining off constructors

2008-06-06 Thread Christoph Boget
Is there a reason why you can't do method chaining off of constructors?

Consider the following class:

  class bob
  {
public function __construct()
{
  echo 'Constructor()';
}

public function one()
{
  echo '->one()';
  return $this;
}

public function two()
{
  echo '->two()';
  return $this;
}
  }

This works:

  $bob = new bob();
  $bob->one()->two();

whereas this doesn't.

  $bob = new bob()->one()->two();

Why?  I thought constructors returned the object?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Method chaining off constructors

2008-06-06 Thread Christoph Boget
> > Why?  I thought constructors returned the object?
> It's been a while since I've played with objects in PHP, but couldn't
> you just add the line:
> return $this;
> ...to the end of your __construct() function? Sorry if this is obtuse of
> me to say, I just thought maybe the answer was that simple and you're
> like I am--you've been staring at a tree for so long, racking your
> brain, that you forget about the forest altogether. :)

The constructor should already be returning $this.

thnx,
Christoph


  

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Method chaining off constructors

2008-06-06 Thread Christoph Boget
> The 'new' keyword has to apply to the object created in the constructor (and
> not the return value of any of the follow-up calls.)   To establish this
> precedence, chaining wasn't  allowed on constructors.

If precedence was the issue, why doesn't this work, either:

(new bob())->one()->two()

?  Or, rather, why couldn't that have been taken into consideration?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Inspiration for a Tombstone.

2008-06-26 Thread Christoph Boget
> "Always on the edge of greatness"

"Tripped on his way to the edge of greatness"

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Inspiration for a Tombstone.

2008-06-26 Thread Christoph Boget
> if ($user_name = "Dan Brown") {
>  echo "GOING DOWN?!";
> } else {
>  echo "Welcome to Heaven";
> }

So I guess that means we're all on the express elevator down.  Looks
like it'll get awfully full... :p

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Code beautifier

2008-07-24 Thread Christoph Boget
> Anyone know of an unintrusive code beautifier written specifically with in 
> mind?

I know it's not quite what you are asking, but the IDE I use has a
really good code beautifier.  It works with a great many languages,
not just for PHP.  This is on top of a gagillion other really useful
features that make coding a lot more fun.

http://www.slickedit.com/

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Object overhead vs. arrays

2008-08-07 Thread Christoph Boget
I knew that there would be some overhead when working with objects vs
working with arrays, but I didn't expect this much.  Is there some
optimization that I could do to improve the performance any?  While
the script below is just a benchmark test script, it approximates
functionality that I'm going to need to implement.  Ultimately, I need
to iterate through a large amount of data and am wondering if perhaps
I should encapsulate the data in objects (which closer represents the
underlying data) or if I should encapsulate it in arrays.  Based on
what I'm seeing in this benchmark script, it seems like it should be
the latter...

Advice and/or input would be much appreciated!

thnx,
Christoph

sVar1 = $sValue;
}

public function setVar2( $sValue )
{
  $this->sVar2 = $sValue;
}

public function setVar3( $sValue )
{
  $this->sVar3 = $sValue;
}

public function setVar4( $aValue )
{
  $this->aVar4 = $aValue;
}
  }

  $iMaxIterations = rand( 1, 123456 );
  $iMaxElements   = rand( 1, 10 );
  $aMasterArraysArray = array();
  $aMasterObjsArray   = array();

  $aWorkingTmp = array();
  for( $i = 0; $i <= $iMaxElements; $i++ )
  {
$aWorkingTmp[] = 'Testing';
  }

  $iStartTime = microtime( TRUE );
  for( $i = 0; $i < $iMaxIterations; $i++ )
  {
$aTmp = array();
$aTmp['var1'] = rand();
$aTmp['var2'] = rand();
$aTmp['var3'] = rand();
$aTmp['var4'] = $aWorkingTmp;

$aMasterArraysArray[] = $aTmp;
  }
  $iEndTime = microtime( TRUE );

  $iArrayTotalTime = ( $iEndTime - $iStartTime );

  echo $iArrayTotalTime . ' seconds elapsed for [' . $iMaxIterations .
'] iterations for ARRAY.';

  $iStartTime = microtime( TRUE );
  for( $i = 0; $i < $iMaxIterations; $i++ )
  {
$oTmp = new TestObj();
$oTmp->setVar1( rand());
$oTmp->setVar2( rand());
$oTmp->setVar3( rand());
$oTmp->setVar4( $aWorkingTmp );

$aMasterObjsArray[] = $oTmp;
  }
  $iEndTime = microtime( TRUE );

  $iObjectTotalTime = ( $iEndTime - $iStartTime );

  echo $iObjectTotalTime . ' seconds elapsed for [' . $iMaxIterations
. '] iterations for OBJECTS.';

  if( $iArrayTotalTime > $iObjectTotalTime )
  {
echo 'Arrays took [' . ( $iArrayTotalTime - $iObjectTotalTime ) .
'] seconds longer,
  a factor of [' . ( $iArrayTotalTime / $iObjectTotalTime ) . ']';
  }
  else
  {
echo 'Objects took [' . ( $iObjectTotalTime - $iArrayTotalTime ) .
'] seconds longer,
  a factor of [' . ( $iObjectTotalTime / $iArrayTotalTime ) . ']';
  }

?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] A few questions about PHP's SOAP module

2008-08-07 Thread Christoph Boget
* I'm trying to better understand the 'classmap' option for the
SoapClient class.  Is it used to define the class of an instantiated
object which will be passed as an argument to the server's function
call?  So, as a very simplistic example, it might go something like
this:

sStockSymbol = $sStockSymbol;
}
  }

  $oObj = new MyClass( 'ibm' );
  $oClient = new SoapClient( $sWSDL_URI, array( 'classmap' => array(
'StockSymbol' => 'MyClass' )));

  $oClient->getStockValue( $oObj );
?>

Am I even close?  Now, what happens if one of the required arguments
to the server function is a variable that has a hyphen in it?  Is
there any way I can get around that since PHP doesn't allow you to
define variables with hyphens?

* Whether using class/objects to pass parameters to a server function
(assuming I have the above correct) or arrays, how can you define
further attributes for each parameter?  Is that even possible?  So
here is an example of a SOAP message that the server is expecting:


http://schemas.xmlsoap.org/soap/envelope/";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
  

  Var1 Value
  live
  

  

  Node Value
  Node Value
  Node Value
  Node Value
  Node Value

  
  

  

  


How can I set up the attributes illustrated above?  Encoding,
node-type, etc?  Is that possible?

* Finally, is there a really good and/or comprehensive tutorial and/or
write-up on PHPs SOAP module?  The documentation is pretty spartan and
what I have found doesn't really go in to much depth.

Any help would be greatly appreciated!

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] More SOAP questions. Also, SOAP bug? Or just me? (long)

2008-08-08 Thread Christoph Boget
* I'm not sure if this is a bug (unlikely) or if it's just me (highly
likely).  Given the following WSDL,


http://schemas.xmlsoap.org/wsdl/soap/";
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/";
xmlns="http://schemas.xmlsoap.org/wsdl/"; name="TestTesting"
targetNamespace="urn:/test/testing">
  
http://www.w3.org/2001/XMLSchema";
xmlns="urn:/test/testing/soap/security/types"
elementFormDefault="qualified"
targetNamespace="urn:/test/testing/soap/security/types">
  

  


  

  

http://www.w3.org/2001/XMLSchema";
xmlns="urn:/test/testing/types" elementFormDefault="qualified"
targetNamespace="urn:/test/testing/types">
  
  

  




  

  

  

  

  

  
  

  
  

  
  

  
  

  
  
http://schemas.xmlsoap.org/soap/http"/>

  
  

  
  

  

  
  


  http://www.testserver.com"/>

  


I have the following code for calling the "ServerOperation" operation:

$oClient = new SoapClient( $sWSDL_URI,
array( 'trace' => TRUE,
 'exceptions'  => FALSE ));

$aParameters = array( 'authentication'  => array( 'username' => 'user',

'password' => 'pass' ),
  'stringvar1'  => 'here',
  'stringvar2'  => 'there',
  'data-array'  =>
'Bob' );

$oClient->ServerOperation( $aParameters );

But running that gives me a soap fault.  Apparently the "data-array"
node isn't populated in the SOAP message body.  I actually get a
different soap fault if I try to use classmap, but that is part of a
different question asked below.  So I then add in:

echo 'Types: ' . print_r( $oClient->__getTypes(), TRUE ) . '';

and it turns out that the "data-array" definition in the WSDL is
getting translated as the following structure:

[XX] => struct data-array {
  any;
}

Umm, huh?  What's going on there?  Why is the SoapClient the part of
the namespace included in the definition for the type in the WSDL
() and turning the "any" into an
attribute of the structure?  So in order to get the "data-array" node
in the SOAP message body, I have to change the parameters definition
to:

$aParameters = array( 'authentication'  => array( 'username' => 'user',

'password' => 'pass' ),
  'stringvar1'  => 'here',
  'stringvar2'  => 'there',
  'data-array'  => array( 'any' =>
'Bob' ));

That seems exceptionally silly to me.  Is this a bug in the
SoapClient's translation of the WSDL?  A problem with the WSDL?  Or a
problem with my (albeit simplistic) code and is something I can and
should get around using proper attributes?  If it's the latter, how
can I define attributes for the various nodes?

* Now, this question is sort of an extension of the issue above.  If
instead of passing in an array, I use the classmap option for the
SoapClient, I get a different soap fault but it's based on the same
problem.  If instead my code looks like this:

$oClient = new SoapClient( $sWSDL_URI,
array( 'trace'   => TRUE,
 'exceptions'  => FALSE,
 'classmap'=>
array( 'ServerOperation' => 'MyClass' )));

and populate public properties of an instance of MyClass with the
appropriate values, the fault message I get then is instead "Encoding:
object hasn't 'any' property".  By setting the "data-array" property
(using variable gymnastics because PHP doesn't like dashes in variable
names) as an array with an "any" key, just as I did above when using
the array, then the fault goes away.  However, it then gives me a
different fault but that is another question asked below.  So again,
is there something different I should be doing that can or does deal
with this?  Is it a bug?

* Finally, the last soap fault message I'm getting (alluded to above)
is one that is telling me that there was no POST data.  I see that the
SOAP envelope/body is populated with all the nodes and data the
operation is expecting but didn't ultimately get.  It seems to me that
when the SoapClient is making the remote function call, it is passing
the data as part of a GET.  Is it possible to tell the soap client
that it should use POST instead?  I don't see anything in the
documentation the deals and/or discusses this.

Any help and/or advice would be greatly appreciated!

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: More SOAP questions. Also, SOAP bug? Or just me? (long)

2008-08-11 Thread Christoph Boget
> different question asked below.  So I then add in:
>
> echo 'Types: ' . print_r( $oClient->__getTypes(), TRUE ) . '';
>
> and it turns out that the "data-array" definition in the WSDL is
> getting translated as the following structure:
>
> [XX] => struct data-array {
>  any;
> }
>
> Umm, huh?  What's going on there?  Why is the SoapClient the part of
> the namespace included in the definition for the type in the WSDL
> () and turning the "any" into an
> attribute of the structure?  So in order to get the "data-array" node
> in the SOAP message body, I have to change the parameters definition
> to:
>
> $aParameters = array( 'authentication'  => array( 'username' => 'user',
>
> 'password' => 'pass' ),
>  'stringvar1'  => 'here',
>  'stringvar2'  => 'there',
>  'data-array'  => array( 'any' =>
> 'Bob' ));
>
> That seems exceptionally silly to me.  Is this a bug in the
> SoapClient's translation of the WSDL?  A problem with the WSDL?  Or a
> problem with my (albeit simplistic) code and is something I can and
> should get around using proper attributes?  If it's the latter, how
> can I define attributes for the various nodes?

It seems like this is having an additional affect of not allowing the
'classmap' functionality to work properly.  When I do:

$oClient->__getLastResponse()

I see the full SOAP message XML and it appears to be properly formed.
So (unless I am profoundly misunderstanding how classmap works) it
should be when I try to do:

$oResponse = $oClient->ServerOperation( $aParameters );

the $oResponse object should be instantiated with it's attributes
populated with the proper values, corresponding with the various
nodes/values that appear in the XML SOAP response.  The problem is, it
isn't.  I've tried creating __get() and __set() methods in the class
to see if they are being called and/or what is getting passed in (if
anything) and I'm not seeing any of my debug outout.  Additionally, if
I run

var_export( $oResponse );

I am seeing:

MyResponseClass::__set_state(array(
   'any' => '',
))

That doesn't seem right.  Further, if I try to access the "any"
property of the object, there is no value (as illustrated above).
It's as if nothing was done with the XML SOAP response w/r/t defining
the classmap option.

So what's going on?  Am I doing something wrong?  Am I totally
misunderstanding something here?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Class diagram util

2008-08-13 Thread Christoph Boget
I'm curious, what utilities do you guys use, if any at all, to map
out/diagram your classes?  I'm looking for a decent (I don't really
need a ton of bells and whistles) freeware app but my searches thus
far have proven fruitless.

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] FCKEditor, TinyMCE, ... I need a light weight WYSIWYG HTML Editor

2008-08-18 Thread Christoph Boget
>> A textarea is a simple editor, I am assuming you want something better than
>> that, or you wouldn't have looked further.
> I just tried Demo and got this:
> "Sorry, you must have Internet Explorer 5.5 or higher to use the WYSIWYG
> editor"
> ?!?

Wow.  You know people who are still using IE5.5?  Seriously?

Textareas do have their problems but I wouldn't consider IE5.5 one of them... :p

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Attributes vs. Accessors

2008-08-25 Thread Christoph Boget
>> Curious. Which do you prefer and why?
>> For publicly-declared variables, do you access the attribute directly or
>> use an accessor?
> If it's a public member variable there is no need for plain accessor methods
> - they add no value. I feel the same about private variables with plain get
> and set accessors, there's just no point unless the accessors are doing more
> than setting and getting the internal variable.

Personally, I always use the accessor methods.

For the most part I agree with Stut -- they don't add much value.
Where it does add value, though, is in the eventuality you ever need
to change the attribute to a more restrictive visibility.  If you ever
run across this need (and I have a couple of times), the only thing
affected is the class; you don't have to worry about changing all of
your code using that class.  Conceptually, it is my preference to keep
a class as much of a black box as possible and accessor methods allow
for that.

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] SOAP call

2008-09-09 Thread Christoph Boget
Is there a way to call a SOAP function and pass the required XML as an
argument instead of an object?  I can get this to work:

$oClient = new SoapClient( $sWSDL_URI, array( 'trace' => TRUE,
'exceptions'=> TRUE );

$oArgObj = new ArgObj();
$oArgObj->node1 = 'value'
$oArgObj->node2 = 'value'
$oArgObj->node3 = 'value'

$oClient->doMyAction( $oArgObj );

but not this:

$oClient = new SoapClient( $sWSDL_URI, array( 'trace' => TRUE,
'exceptions'=> TRUE );

$sXML = 
'valuevaluevalue';

Which, if I look at the result from __getLastRequest(), is exactly
what the XML sent looks like (minus the SOAP body, etc).

The error I keep gettings is "xml-resolve-missing-var-error".  Is
there any way I can just send the XML?  Or does it have to be an
object with the appropriate properties set?

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Static method variable

2008-09-18 Thread Christoph Boget
Perhaps I'm misunderstanding what a static method variable is supposed
to do.  I thought the value would be static for an class' instance but
it appears it is static across all instances of the class.  Consider:

class StaticTest
{
  public function __construct()
  {
  }

  public function test( $newVal )
  {
static $retval = '';

if( $retval == '' )
{
  $retval = $newVal;
}
echo $retval . '';
  }
}

$one = new StaticTest();
$one->test( 'joe' );
$two = new StaticTest();
$two->test( 'bob' );

Should it be working that way?

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Singletons

2008-10-20 Thread Christoph Boget
Ok, so why isn't this working as (I, at the very least) expected?

  class singleTon
  {
private static $thisObj = NULL;
private $thisProp = NULL;

public function __construct()
{
echo 'singleTon::__construct()';
  if( !is_null( singleTon::$thisObj ))
  {
echo '$thisObj already set.  returning it...';
return singleTon::$thisObj;
  }
  singleTon::$thisObj = $this;
}

public static function singleton()
{
echo 'singleTon::singleton()';
  if( is_null( singleTon::$thisObj ))
  {
$retval = new singleTon();
  }
  return singleTon::$thisObj;

}

public function setThisProp( $sVal )
{
  $this->thisProp = $sVal;
}

public function getThisProp()
{
  return $this->thisProp;
}
  }

  $one = singleTon::singleton();
  $one->setThisProp( 'Joe' );
  echo '$one->getThisProp();: [' . $one->getThisProp() . ']';
  echo '$one: [' . var_export( $one, TRUE ) . ']';
  $two = new singleTon();
  echo '$two->getThisProp();: [' . $two->getThisProp() . ']';
  $two->setThisProp( 'Bob' );
  echo '$two: [' . var_export( $two, TRUE ) . ']';
  echo '$one->getThisProp();: [' . $one->getThisProp() . ']';
  echo '$two->getThisProp();: [' . $two->getThisProp() . ']';
  echo '$one->getThisProp();: [' . $one->getThisProp() . ']';

I would have thought that both $one and $two would be referencing the
same object but they aren't.  Apart from making the constructor
private, is there any way I can ensure that there is ever only one
instance of an object?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Singletons

2008-10-20 Thread Christoph Boget
>> Apart from making the constructor
>> private, is there any way I can ensure that there is ever only one
>> instance of an object?
> you could use the magic method __clone.
> For example:
> public function __clone() { trigger_error('The singleton pattern avoids
> cloning this instance', E_USER_ERROR); }

Adding the above to my sample class (from my OP) did nothing.  Should it have?

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Singletons

2008-10-20 Thread Christoph Boget
>>   public function __construct()
> A singleton would usually have a private constructor to prevent
> non-singleton instances.

The problem being if the class in question derives from another class
that has a public constructor...  If you are in that particular
situation (which I am), you're basically SOL and the statement above
has no bearing.

>>   {
>> echo 'singleTon::__construct()';
>> if( !is_null( singleTon::$thisObj ))
>> {
>> echo '$thisObj already set.  returning it...';
>>   return singleTon::$thisObj;
>> }
>> singleTon::$thisObj = $this;
> 1) You don't return it unless it already exists, not that it matters because
> this is the constructor and you can't return anything from that.

> 2) The constructor has no involvement in management of the singleton
> instance so this is just all wrong.

I did this mainly to see if it would have any effect.

>>   public static function singleton()
>>   {
> That method has the same name as the class. I'm not sure what effect this
> will have but it's certainly to be discouraged.

It has no effect.  And yes, that is true in general, but this is just
a test foobar class.

> Here's the simplest example I can think of (untested, typed straight into my
> mail client)...

This won't work if derived from a class with a public constructor.
That's why my test class' constructor was defined public.

> Singletons are not rocket science, but as with all patterns you really need
> to understand the theory before trying to implement and use it.

Agreed.  But apparently implementing them in PHP leaves things to be desired.

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Singletons

2008-10-20 Thread Christoph Boget
> There is absolutely nothing in PHP which prevents you from implementing the
> singleton pattern.

It does if the constructor must be public.

> but your attempt is doomed to failure. What makes you think that a singleton
> class has to inherit from another class?

Nothing at all.  Except that in my particular case, I do need to
inherit from another class which has a public constructor.  And the
class I'm trying to write needs to be a singleton.

I guess that teaches me not to post a question without including a
doctoral thesis about what it is I'm trying to do.  I figured just
including the most base and/or basic parts of what I was dealing with
would be sufficient.  Though, I will say I probably shouldn't have
included all of that junk in the constructor in my OP.  That was just
a hail-mary-pray-it-might-be-a-workable-workround on my part.  I was
pretty sure it wouldn't be, but *shrug*

> Why can't it be a separate class,

In general, it can.  In my case, it can't.  Not unless I want to
completely duplicate an already existing class.

> or even a separate method in an existing class? If you use a static method
> then the activities of the constructor are irrelevant.

They aren't irrelevant if the class can be instantiated directly.
That sort of kind of breaks the whole singleton thing...

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Singletons

2008-10-20 Thread Christoph Boget
> Create your singleton class without extending the class you need to extend.
> Create an instance of that class in your object. Implement the __call magic
> method to proxy function calls through to that instance throwing an
> exception (or error) if the method requested doesn't exist. Not particularly
> pretty, but definitely simple.

No, not pretty at all though it would address my issues.  Thanks for the idea!

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Singletons

2008-10-22 Thread Christoph Boget
> here is in my opinion, what you can do:
> class Base {
>  private function __construct()

Except that in one of my follow up posts I indicated that my singleton
class was deriving from a class that had a public constructor.

Thanks anyway.  I ended up just using Stut's suggestion.  As he said,
it's not pretty but it is simple.

thnx,
Christoph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] class constructor overloading

2008-10-23 Thread Christoph Boget
>> is it possible to overload the class construct(or) ?
>> if yes, how ?

No, it's not.

> class A
> {
>function __construct()
>{
>echo "A";
>}
> }
>
> class B extends A
> {
>function __construct()
>{
>echo "B";
>parent::__construct();
>}
> }
> $B = new B();

The above is an example of overriding, not overloading; PHP allows the
former but not the latter.

Examples of overloading include:

class A
{
  function myFunc( $boolean )
  {

  }

  function myFunc( $string )
  {

  }

  function myFunc( $array )
  {

  }
}

Because PHP is loosely typed, the above is largely moot/unnecessary.

class B
{
  function myFunc( $boolean )
  {

  }

  function myFunc( $boolean, $string )
  {

  }

  function myFunc( $boolean, $string, $array )
  {

  }
}

PHP allows you to get around the above by allowing you to define
default values for arguments.  Doing that is kind of like overloading
but only in a fake-me-out kind of way.  So instead of overloading the
myFunc method, you could just define it as follows:

class B
{
  function myFunc( $boolean = FALSE, $string = '', $array = array())
  {

  }
}

but even that doesn't ensure that the data type of each argument is as
you might expect.  As I stated above, PHP is loosely typed so there is
nothing preventing, say, the $string argument from actually being a
numeric datatype.  If you are using PHP5+, you can sort of get around
that by using type hinting
(http://us.php.net/manual/en/language.oop5.typehinting.php) but you
can only type hint objects and arrays.

In closing, to answer your question,

Overriding: yes
Overloading: no

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php