php-general Digest 4 Nov 2009 15:48:09 -0000 Issue 6426

Topics (messages 299600 through 299618):

Re: Custom function for inserting values into MySQL
        299600 by: Shawn McKenzie

Re: shell_exec fails to compile java class?
        299601 by: Nathan Rixham
        299602 by: Nathan Rixham

Re: What PHP version are you using?
        299603 by: Nathan Rixham
        299604 by: Nathan Rixham
        299609 by: Ashley Sheridan

Re: Two Parser Passes
        299605 by: Nathan Rixham
        299606 by: Nathan Rixham

Re: Classes and Functions
        299607 by: Nathan Rixham
        299608 by: Nathan Rixham

Re: Apache file order
        299610 by: Nathan Rixham

Re: PHP String convention
        299611 by: Nathan Rixham
        299614 by: Lars Torben Wilson
        299616 by: Lars Torben Wilson

Re: It's not behaving. Error reporting, that is
        299612 by: Philip Thompson
        299613 by: Ashley Sheridan
        299615 by: Nathan Rixham

Re: Using remote include config file and class in a local file
        299617 by: Nathan Rixham

Re: Need unrounded precision
        299618 by: Matthew McKay

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
In your example, I would name my form inputs similar to name
="data[user_id]".

Then you just pass the $_POST['data'] array to your function.

-Shawn

Allen McCabe wrote:
> You raise some good points. I always name my input fields after the
> entity names ( eg. input type="hidden" name ="user_id" value=" ?php
> echo $resultRow['user_id'] ? " ).
>
> I suppose I am still in the phase of learning efficiency, and perhaps
> trying to 'get out it' by writing functions that I can just call and
> pass parameters instead of fully learning the core concepts.
>
> I just think functions are so damn cool :)
>
>
>     I'll echo what the others have said about the parameters.  For me
>     personally, if I am passing more than three parameters (sometimes even
>     three) I rethink my function.  I'm not sure what you envision
>     using this
>     function for, but the approach I use for forms and databases is always
>     arrays.  I get an array from my forms, I insert that array into the
>     database, and of course I fetch arrays out of the database.  These are
>     all indexed the same with the index as the field name of the table so
>     it's easy.
>
>
>     --
>     Thanks!
>     -Shawn
>     http://www.spidean.com
>
>
>

--- End Message ---
--- Begin Message ---
דניאל דנון wrote:
Hello!

I need to use shell_exec (or any other similar function) in order to compile
a java class-file.

I have all the needed components installed on my computer (Windows XP with
Java SDK) - I can use "java c:\path...." in order to compile using
Start->Run.

When I try to do the same with shell_exec or `` it returns null and it
doesn't compiles. Even when there are errors - it doesn't show them at all.

I've tried to use instead of "java c:\path..." the full java command line
compiler path but it didn't work either.


When I try functions such as "echo test" it works.


Clearly I'm missing here something - problem is... what?


create an ant builder or .bat and call that instead; most likely because the environment isn't set up correctly when executing via php; thus when using ant or bat you can set everything up correctly as needed.

always use PHP on linux but permissions and the scope / permissions of the account php runs under may come in to play?

nathan

--- End Message ---
--- Begin Message ---
דניאל דנון wrote:
Hello!

I need to use shell_exec (or any other similar function) in order to compile
a java class-file.

I have all the needed components installed on my computer (Windows XP with
Java SDK) - I can use "java c:\path...." in order to compile using
Start->Run.

When I try to do the same with shell_exec or `` it returns null and it
doesn't compiles. Even when there are errors - it doesn't show them at all.

I've tried to use instead of "java c:\path..." the full java command line
compiler path but it didn't work either.


When I try functions such as "echo test" it works.


Clearly I'm missing here something - problem is... what?


create an ant builder or .bat and call that instead; most likely because the environment isn't set up correctly when executing via php; thus when using ant or bat you can set everything up correctly as needed.

always use PHP on linux but permissions and the scope / permissions of the account php runs under may come in to play?

nathan

--- End Message ---
--- Begin Message ---
Israel Ekpo wrote:
Hi Guys,

I just want to conduct a quick survey to find out what version of PHP people
are using in their production environments.

I have a PHP extension for Solr that I have set the minimum required version
as 5.2.11.

http://pecl.php.net/package/solr/

However, most of the PHP users that want to use it are unable to do so
because the PHP version in the PROD environments is below 5.2.11

They are also nervous about upgrading to newer versions as it will require
some regression testing.

In my production environment I am using 5.3.0 and most of the people that I
have contacted seems to be running 5.2.10

When I released the extension, I did all my regression tests against PHP
5.2.11 and now I am considering doing regression tests against 5.2.4
(released 30 August 2007)  and newer versions so that I can set the minimum
required version to 5.2.4 in order to accommodate more people.

I cannot go below 5.2.0 though but I am thinking about starting at 5.2.4 and
newer.

I would really appreciate some feedback as it will be useful in helping me
determine which PHP version numbers to do my regression tests against.

Thanks.


PHP 5.2.4-2 on most production boxes
mixed 5.1.6, 5.2 and 5.3's in dev environments

+ interesting release; wish I'd known spent part of the first week in october doing a SOLR integration in PHP *sigh* - on to virtuoso now
--- End Message ---
--- Begin Message ---
Israel Ekpo wrote:
Hi Guys,

I just want to conduct a quick survey to find out what version of PHP people
are using in their production environments.

I have a PHP extension for Solr that I have set the minimum required version
as 5.2.11.

http://pecl.php.net/package/solr/

However, most of the PHP users that want to use it are unable to do so
because the PHP version in the PROD environments is below 5.2.11

They are also nervous about upgrading to newer versions as it will require
some regression testing.

In my production environment I am using 5.3.0 and most of the people that I
have contacted seems to be running 5.2.10

When I released the extension, I did all my regression tests against PHP
5.2.11 and now I am considering doing regression tests against 5.2.4
(released 30 August 2007)  and newer versions so that I can set the minimum
required version to 5.2.4 in order to accommodate more people.

I cannot go below 5.2.0 though but I am thinking about starting at 5.2.4 and
newer.

I would really appreciate some feedback as it will be useful in helping me
determine which PHP version numbers to do my regression tests against.

Thanks.


PHP 5.2.4-2 on most production boxes
mixed 5.1.6, 5.2 and 5.3's in dev environments

+ interesting release; wish I'd known spent part of the first week in october doing a SOLR integration in PHP *sigh* - on to virtuoso now


--- End Message ---
--- Begin Message ---
On Wed, 2009-11-04 at 14:37 +0000, Nathan Rixham wrote:

> Israel Ekpo wrote:
> > Hi Guys,
> > 
> > I just want to conduct a quick survey to find out what version of PHP people
> > are using in their production environments.
> > 
> > I have a PHP extension for Solr that I have set the minimum required version
> > as 5.2.11.
> > 
> > http://pecl.php.net/package/solr/
> > 
> > However, most of the PHP users that want to use it are unable to do so
> > because the PHP version in the PROD environments is below 5.2.11
> > 
> > They are also nervous about upgrading to newer versions as it will require
> > some regression testing.
> > 
> > In my production environment I am using 5.3.0 and most of the people that I
> > have contacted seems to be running 5.2.10
> > 
> > When I released the extension, I did all my regression tests against PHP
> > 5.2.11 and now I am considering doing regression tests against 5.2.4
> > (released 30 August 2007)  and newer versions so that I can set the minimum
> > required version to 5.2.4 in order to accommodate more people.
> > 
> > I cannot go below 5.2.0 though but I am thinking about starting at 5.2.4 and
> > newer.
> > 
> > I would really appreciate some feedback as it will be useful in helping me
> > determine which PHP version numbers to do my regression tests against.
> > 
> > Thanks.
> > 
> 
> PHP 5.2.4-2 on most production boxes
> mixed 5.1.6, 5.2 and 5.3's in dev environments
> 
> + interesting release; wish I'd known spent part of the first week in 
> october doing a SOLR integration in PHP *sigh* - on to virtuoso now
> 
> 


5.2.9 on my home laptop and main box (used for devel)
4.4.7 on my own site (stupid hosting company are useless!)
and a mix of 5.x's on the sites I develop

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Daniel Kolbo wrote:
Steve wrote:
Daniel Kolbo wrote:
Hello,

Is it possible to get a list (array) of classes not found in a script
before the fatal error exits the parser.  I realize that PHP parses the
script twice.  It would be nice at the end of the first parsing pass to
check to see which classes haven't been defined (yet), so that I could
define them before the second pass.  This way I could load only those
classes a script needs.

Thanks in advance,
dK
`
It sounds like you are looking for autoload:
http://www.php.net/manual/language.oop5.autoload.php


Mr. Steve that's pretty cool.  Thanks.

Is there a similar type function for autoloading undefined functions?

Thanks,
dK
`

not afaik, but you should be able to hack it by catching errors, checking for undefined functions then loading your.lib.php file

imho it'd make more sense to wrap misc functions in a class or two as static methods though then you can take advantage of the autoloading.

also if you can use spl autoloading and registration so it plays nice with other libs.

regards

--- End Message ---
--- Begin Message ---
Daniel Kolbo wrote:
Steve wrote:
Daniel Kolbo wrote:
Hello,

Is it possible to get a list (array) of classes not found in a script
before the fatal error exits the parser.  I realize that PHP parses the
script twice.  It would be nice at the end of the first parsing pass to
check to see which classes haven't been defined (yet), so that I could
define them before the second pass.  This way I could load only those
classes a script needs.

Thanks in advance,
dK
`
It sounds like you are looking for autoload:
http://www.php.net/manual/language.oop5.autoload.php


Mr. Steve that's pretty cool.  Thanks.

Is there a similar type function for autoloading undefined functions?

Thanks,
dK
`

not afaik, but you should be able to hack it by catching errors, checking for undefined functions then loading your.lib.php file

imho it'd make more sense to wrap misc functions in a class or two as static methods though then you can take advantage of the autoloading.

also if you can use spl autoloading and registration so it plays nice with other libs.

regards

--- End Message ---
--- Begin Message ---
Daniel Kolbo wrote:
Hello,

Is there a way to see what objects and functions a script
loaded/required/used?

I could recursively loop through the globals, but if objects were unset,
then i may miss some.

I could make a 'tracking' object and every time i load/include a file
(which contains a class def or a function def) to add that file to the
tracking object...but it would be nice if i didn't have to modify my
existing code to see which objects and functions a script actually used,
or at least, requested and loaded into memory.

Thanks in advance,
Daniel Kolbo
`


if it's for debugging, get a good debugger so you can inspect at break points; for use during runtime and something "scripted" you can call the relevant get_defined/declared functions before before your app does it's loading, then the same later on and compare to get a definitive list.

also worth asking if you're refering to objects (as in instances) or classes.

Object = instance of a Class [ $object = new Class() ]

--- End Message ---
--- Begin Message ---
Daniel Kolbo wrote:
Hello,

Is there a way to see what objects and functions a script
loaded/required/used?

I could recursively loop through the globals, but if objects were unset,
then i may miss some.

I could make a 'tracking' object and every time i load/include a file
(which contains a class def or a function def) to add that file to the
tracking object...but it would be nice if i didn't have to modify my
existing code to see which objects and functions a script actually used,
or at least, requested and loaded into memory.

Thanks in advance,
Daniel Kolbo
`


if it's for debugging, get a good debugger so you can inspect at break points; for use during runtime and something "scripted" you can call the relevant get_defined/declared functions before before your app does it's loading, then the same later on and compare to get a definitive list.

also worth asking if you're refering to objects (as in instances) or classes.

Object = instance of a Class [ $object = new Class() ]

--- End Message ---
--- Begin Message ---
Skip Evans wrote:
Hey all,

I modified an Apache config file to list the HTML file first, after the PHP file, it still pulls up the PHP file first.

Is there another setting in Apache I should be looking for?

I need it to check for the HTML file first.

Thanks,
Skip

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>



yup it may be in the .htaccess as well :)

--- End Message ---
--- Begin Message ---
Nick Cooper wrote:
Hi,

I was just wondering what the difference/advantage of these two
methods of writing a string are:

1) $string = "foo{$bar}";

2) $string = 'foo'.$bar;

1) breaks PHPUnit when used in classes (need to bug report that)
2) [concatenation] is faster (but you wouldn't notice)

comes down to personal preference and what looks best in your (teams) IDE I guess; legibility (and possibly portability) is probably the primary concern.


--- End Message ---
--- Begin Message ---
2009/10/28 Warren Vail <[email protected]>:
> The curly braces look like something from the smarty template engine.
>
> Warren Vail

Odd. I always thought the curly braces in the Smarty engine looked
like something from PHP. :)


Torben

> -----Original Message-----
> From: Kim Madsen [mailto:[email protected]]
> Sent: Wednesday, October 28, 2009 10:18 AM
> To: Nick Cooper
> Cc: Jim Lucas; [email protected]
> Subject: Re: [PHP] PHP String convention
>
> Hi Nick
>
> Nick Cooper wrote on 2009-10-28 17:29:
>
>> Thank you for the quick replies. I thought method 2 must be faster
>> because it doesn't have to search for variables in the string.
>>
>> So what is the advantages then of method 1 over 3, do the curly braces
>> mean anything?
>>
>> 1) $string = "foo{$bar}";
>>
>> 2) $string = 'foo'.$bar;
>>
>> 3) $string = "foo$bar";
>>
>> I must admit reading method 1 is easier, but writing method 2 is
>> quicker, is that the only purpose the curly braces serve?
>
> Yes, you're right about that. 10 years ago I went to a seminar were
> Rasmus Lerforf was speaking and asked him exactly that question. The
> single qoutes are preferred and are way faster because it doesn´t have
> to parse the string, only the glued variables.
>
> Also we discussed that if you´re doing a bunch of HTML code it's
> considerably faster to do:
>
> <tr>
>   <td><?= $data ?></td>
> </tr>
>
> Than
> print "
> \n\t<tr>
>   \n\t\t<td>$data</td>
> \n\t</tr>";
>
> or
> print '
> <tr>
>   <td>'.$data.'</td>
> </tr>';
>
> I remember benchmark testing it afterwards back then and there was
> clearly a difference.
>
> --
> Kind regards
> Kim Emax - masterminds.dk
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
2009/11/4 Nathan Rixham <[email protected]>:
> Nick Cooper wrote:
>>
>> Hi,
>>
>> I was just wondering what the difference/advantage of these two
>> methods of writing a string are:
>>
>> 1) $string = "foo{$bar}";
>>
>> 2) $string = 'foo'.$bar;
>
> 1) breaks PHPUnit when used in classes (need to bug report that)
> 2) [concatenation] is faster (but you wouldn't notice)
>
> comes down to personal preference and what looks best in your (teams) IDE I
> guess; legibility (and possibly portability) is probably the primary
> concern.

I would tend to agree here; the concat is faster but you may well only
notice in very tight loops. The curly brace syntax can increase code
readability, depending on the complexity of the expression. I  use
them both depending on the situation.

Remember the rules of optimization:

1) Don't.
2) (Advanced users only): Optimize later.

Write code so that it's readable, and then once it's working, identify
the bottlenecks and optimize where needed. If you understand code
analysis and big-O etc then you will start to automatically write
mostly-optimized code anyway and in general, I doubt that you'll often
identify the use of double quotes as a bottleneck--it almost always
turns out that other operations and code structures are far more
expensive and impact code speed much more.

That said, you don't really lose anything by using concatenation from
the start, except perhaps some legibility, so as Nathan said it often
really just comes down to personal preference and perhaps the house
coding conventions.


Regards,

Torben

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

--- End Message ---
--- Begin Message ---
On Nov 3, 2009, at 11:24 AM, Kim Madsen wrote:

Hi Philip

Try to post a link to a page, that prints phpinfo()

-- Kind regards
Kim Emax

Philip Thompson wrote on 2009-11-03 17:11:
Hi all.
This seems like a trivial issue to fix, but I'm having issues. I'm running a script via command line and it's throwing out PHP "notices." Well, I want to suppress those notices. At the top of my script I have the line...
<?php
error_reporting (E_ERROR);
?>
...thinking that this would get rid of the notices. However, it did not. They still appear. I even attempted using ini_set(), but to no avail. I then set error_reporting in php.ini - this made no difference. (I shouldn't have to restart apache when running via command line, but for giggles, I did.) I then changed display_errors to Off. You guessed it - no change! This immediately brought up the question... "Well, what php.ini is this script using?" Here's my results...
[pthomp...@s-irv-pthompson scripts]$ php --ini
Configuration File (php.ini) Path: /etc
Loaded Configuration File:         /etc/php.ini
Scan for additional .ini files in: /etc/php.d
...
Yup, according to PHP I'm using the correct ini. Now I'm at a loss. Can anyone shed some light on this big brain fart I'm having? Thanks in advance.
~Philip


--
Kind regards
Kim Emax - masterminds.dk

That's all good and dandy. But this is a cli application. And besides, the computer is not accessible via the Internet.

Thanks,
~Philip

--- End Message ---
--- Begin Message ---
On Wed, 2009-11-04 at 08:52 -0600, Philip Thompson wrote:

> On Nov 3, 2009, at 11:24 AM, Kim Madsen wrote:
> 
> > Hi Philip
> >
> > Try to post a link to a page, that prints phpinfo()
> >
> > --  
> > Kind regards
> > Kim Emax
> >
> > Philip Thompson wrote on 2009-11-03 17:11:
> >> Hi all.
> >> This seems like a trivial issue to fix, but I'm having issues. I'm  
> >> running a script via command line and it's throwing out PHP  
> >> "notices." Well, I want to suppress those notices. At the top of my  
> >> script I have the line...
> >> <?php
> >> error_reporting (E_ERROR);
> >> ?>
> >> ...thinking that this would get rid of the notices. However, it did  
> >> not. They still appear. I even attempted using ini_set(), but to no  
> >> avail. I then set error_reporting in php.ini - this made no  
> >> difference. (I shouldn't have to restart apache when running via  
> >> command line, but for giggles, I did.) I then changed  
> >> display_errors to Off. You guessed it - no change! This immediately  
> >> brought up the question... "Well, what php.ini is this script  
> >> using?" Here's my results...
> >> [pthomp...@s-irv-pthompson scripts]$ php --ini
> >> Configuration File (php.ini) Path: /etc
> >> Loaded Configuration File:         /etc/php.ini
> >> Scan for additional .ini files in: /etc/php.d
> >> ...
> >> Yup, according to PHP I'm using the correct ini. Now I'm at a loss.  
> >> Can anyone shed some light on this big brain fart I'm having?  
> >> Thanks in advance.
> >> ~Philip
> >
> >
> > -- 
> > Kind regards
> > Kim Emax - masterminds.dk
> 
> That's all good and dandy. But this is a cli application. And besides,  
> the computer is not accessible via the Internet.
> 
> Thanks,
> ~Philip
> 


You can call a phpinfo() script from the CLI, but I don't think that's
your problem here. Have you tried setting any other php.ini variables at
all and had any success with that?

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Ashley Sheridan wrote:
On Wed, 2009-11-04 at 08:52 -0600, Philip Thompson wrote:

On Nov 3, 2009, at 11:24 AM, Kim Madsen wrote:

Hi Philip

Try to post a link to a page, that prints phpinfo()

-- Kind regards
Kim Emax

Philip Thompson wrote on 2009-11-03 17:11:
Hi all.
This seems like a trivial issue to fix, but I'm having issues. I'm running a script via command line and it's throwing out PHP "notices." Well, I want to suppress those notices. At the top of my script I have the line...
<?php
error_reporting (E_ERROR);
?>
...thinking that this would get rid of the notices. However, it did not. They still appear. I even attempted using ini_set(), but to no avail. I then set error_reporting in php.ini - this made no difference. (I shouldn't have to restart apache when running via command line, but for giggles, I did.) I then changed display_errors to Off. You guessed it - no change! This immediately brought up the question... "Well, what php.ini is this script using?" Here's my results...
[pthomp...@s-irv-pthompson scripts]$ php --ini
Configuration File (php.ini) Path: /etc
Loaded Configuration File:         /etc/php.ini
Scan for additional .ini files in: /etc/php.d
...
Yup, according to PHP I'm using the correct ini. Now I'm at a loss. Can anyone shed some light on this big brain fart I'm having? Thanks in advance.
~Philip

--
Kind regards
Kim Emax - masterminds.dk
That's all good and dandy. But this is a cli application. And besides, the computer is not accessible via the Internet.

Thanks,
~Philip



You can call a phpinfo() script from the CLI, but I don't think that's
your problem here. Have you tried setting any other php.ini variables at
all and had any success with that?

Thanks,
Ash
http://www.ashleysheridan.co.uk




use -n to specify no ini file
-c /path/to/php.ini to specify and ini file
-d error_reporting=E_ALL to force the directive

and to check you can use
php -i | grep error_reporting


--- End Message ---
--- Begin Message ---
Shawn McKenzie wrote:
Anton Heuschen wrote:
Question is wrt to including a config file on an external server in a
local include

Lets say that on 127.0.0.1 I have test.php with

include http://200.200.1.1/Folder/Config.php

$obj = new RemoteClass()

do stuff


and on server 200.200.1.1 I have my Config.php file which is contains
the class RemoteClass() { echo "test" }



If I try to test it locally it says it cannot find RemoteClass ...


How can I include/require a config (or any other php classes file) on
my local running php script ?

As others have said, you are receiving the output of the config.php
after it has been parsed by PHP on the remote server.  You could try
naming it config.cfg, config.conf, config.ini, config.inc, etc...


multiple choice
- why not use PHAR
- on remote server enable .phps (php source)
- remove "SetHandler application/x-httpd-php" in you apache conf (if on apache, and obviously realise this won't let any php scripts run through http)
- mount the remote file system locally

and.. why? normal approach would be to expose the remote functionality needed as a web service and call it via SOAP/RPC/REST etc

however.. always fancied the idea of a central server for php libs that can be included at runtime (with some local cache'ing and version checking) - would make most sense if we all used a single version of the same libs & only one copy etc etc

regards

--- End Message ---
--- Begin Message ---
Kim Madsen wrote:
Hello

Andre Dubuc wrote on 2010-01-02 02:20:
Hi,

I need to extract the first digit after the decimal point from a number such as 28.56018, which should be '5'.

Since no one came up with the simple solution:

$num = "28.56018";
ereg("^[0-9]+\.([0-9]){1}", trim($num), $regs);
if($regs[1])
  $digit = $regs[1];
else
  print "no digit found";

My submission for a "simple" solution. I wish I had xslt2 =(
<xsl:template name="firstDigit">
   <xsl:param name="number"/>
<xsl:value-of select="number(substring(substring-after(number(translate(normalize-space($number),translate(normalize-space($number),'.0123456789',''),'')),'.'),1,1))"/>
</xsl:template>


--- End Message ---

Reply via email to