Re: [PHP] Functions/methods aliases in PHp 5.2

2011-05-16 Thread David Harkness
On Sun, May 15, 2011 at 3:15 PM, Richard Quadling wrote:

> Personally, I would recommend using 1 naming convention and sticking with
> it.
>

I wholeheartedly agree. Multiple method names is not flexibility--it's
confusion and an open invitation for bugs. Plus, even with two styles you'll
never satisfy everyone. For example I would expect getNumRows() or
getRowCount().

David


Re: [PHP] Functions/methods aliases in PHp 5.2

2011-05-15 Thread Richard Quadling
On 15 May 2011 23:06, Andre Polykanine  wrote:
> Hello Richard,
>
>      I'd  like  to  make  a database wrapping class (yet another one,
> aha!) as flexible, as possible.
> So I'd like to make possible to call, for example,
> $db->num_rows($result)
>                     and
> $db->NumRows($result)
> And was just wondering :-).
>
> --
> With best regards from Ukraine,
> Andre
> Skype: Francophile
> My blog: http://oire.org/menelion (mostly in Russian)
> Twitter: http://twitter.com/m_elensule
> Facebook: http://facebook.com/menelion
>
>  Original message 
> From: Richard Quadling 
> To: Andre Polykanine
> Date created: , 12:48:30 AM
> Subject: [PHP] Functions/methods aliases in PHp 5.2
>
>
>      On 15 May 2011 21:45, Andre Polykanine  wrote:
>> Hi everyone,
>>
>> Is there any possibility to make a method or function alias in PHP?
>> Yes, I know I can do the following:
>>
>> > function foo_bar($x) {
>> // And so we code...
>> return $result;
>> }
>>
>> function FooBar($x) {
>> return foo_bar($x)
>> }
>>
>> But maybe there is a more elegant solution?
>> Thanks!
>
> Whilst you can do class_alias() - something I use to hide the long
> class name for soap services - there isn't a function alias.
>
> But, if you are creating your own functions, then you could use a
> closure and that can be assigned to a variable ...
>
> $fn_FooBar = function() { ... };
>
> $fn_FooBar($a, $b, $c);
>
> or
>
> someFunc($fn_FooBar) { ... }
>
>
> Closures are ideal for callbacks.
>
> Why do you want to alias functions? Is it to obscure the existing name?
>
> If so, take a look at using an encoder. This uses the compiled code
> rather than the source to run.
>
> It is faster to run as there is no compile phase and the "code" isn't
> very easy to reverse.

A couple of things come to mind.

1 - If you create a subclass and were overriding num_rows(), the
subclass would have to also override NumRows(). Twice as much work.

2 - You could use __call() and __callStatic() magic methods, but you'd
have limited options for documentation then (assuming you use
docblocks.

Personally, I would recommend using 1 naming convention and sticking with it.

Richard.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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



Re: [PHP] Functions/methods aliases in PHp 5.2

2011-05-15 Thread Andre Polykanine
Hello Richard,

  I'd  like  to  make  a database wrapping class (yet another one,
aha!) as flexible, as possible.
So I'd like to make possible to call, for example,
$db->num_rows($result)
 and
$db->NumRows($result)
And was just wondering :-).

-- 
With best regards from Ukraine,
Andre
Skype: Francophile
My blog: http://oire.org/menelion (mostly in Russian)
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion

 Original message 
From: Richard Quadling 
To: Andre Polykanine
Date created: , 12:48:30 AM
Subject: [PHP] Functions/methods aliases in PHp 5.2


  On 15 May 2011 21:45, Andre Polykanine  wrote:
> Hi everyone,
>
> Is there any possibility to make a method or function alias in PHP?
> Yes, I know I can do the following:
>
>  function foo_bar($x) {
> // And so we code...
> return $result;
> }
>
> function FooBar($x) {
> return foo_bar($x)
> }
>
> But maybe there is a more elegant solution?
> Thanks!

Whilst you can do class_alias() - something I use to hide the long
class name for soap services - there isn't a function alias.

But, if you are creating your own functions, then you could use a
closure and that can be assigned to a variable ...

$fn_FooBar = function() { ... };

$fn_FooBar($a, $b, $c);

or

someFunc($fn_FooBar) { ... }


Closures are ideal for callbacks.

Why do you want to alias functions? Is it to obscure the existing name?

If so, take a look at using an encoder. This uses the compiled code
rather than the source to run.

It is faster to run as there is no compile phase and the "code" isn't
very easy to reverse.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

-- 
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



Re: [PHP] Functions/methods aliases in PHp 5.2

2011-05-15 Thread Richard Quadling
On 15 May 2011 21:45, Andre Polykanine  wrote:
> Hi everyone,
>
> Is there any possibility to make a method or function alias in PHP?
> Yes, I know I can do the following:
>
>  function foo_bar($x) {
> // And so we code...
> return $result;
> }
>
> function FooBar($x) {
> return foo_bar($x)
> }
>
> But maybe there is a more elegant solution?
> Thanks!

Whilst you can do class_alias() - something I use to hide the long
class name for soap services - there isn't a function alias.

But, if you are creating your own functions, then you could use a
closure and that can be assigned to a variable ...

$fn_FooBar = function() { ... };

$fn_FooBar($a, $b, $c);

or

someFunc($fn_FooBar) { ... }


Closures are ideal for callbacks.

Why do you want to alias functions? Is it to obscure the existing name?

If so, take a look at using an encoder. This uses the compiled code
rather than the source to run.

It is faster to run as there is no compile phase and the "code" isn't
very easy to reverse.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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



Re: [PHP] functions and global variables

2010-07-19 Thread Simcha Younger




On Mon, 19 Jul 2010 13:37:12 +0530
Shreyas Agasthya  wrote:

> My two cents on this one.
> 
> Modify the $name within the function and print it.
> 
> Modify the$name outside the function (means the non-global-declared $name)
> and print it. You will know the difference.
> 
> --Shreyas
> 
> On Mon, Jul 19, 2010 at 7:41 AM, Paul M Foster wrote:
> 
> > On Sun, Jul 18, 2010 at 06:37:30PM -0400, David Mehler wrote:
> >
> > > Hello,
> > > I've got a file with a variable declared in it. For purposes of this
> > post:
> > >
> > > $name = $_POST['name'];

> > >
> > > I'm wondering do I have to have $name declared as a global variable
> > > within that function? For example:
> > >
> > > function customFunction() {
> > > global $name
> > > }
> > >
> > > I've tried it both ways and both ways it works, with and without the
> > > global statement. I was under the impression that to be useful in a
> > > function variables outside were not accessible.
> > > Thanks.
> > > Dave.



It sounds like 'register globals' is turned on in your php.ini, and therefore 
$name will be visible everywhere, since it is taken from $_POST['name'].

-- 
Simcha Younger 

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



Re: [PHP] functions and global variables

2010-07-19 Thread Shreyas Agasthya
My two cents on this one.

Modify the $name within the function and print it.

Modify the$name outside the function (means the non-global-declared $name)
and print it. You will know the difference.

--Shreyas

On Mon, Jul 19, 2010 at 7:41 AM, Paul M Foster wrote:

> On Sun, Jul 18, 2010 at 06:37:30PM -0400, David Mehler wrote:
>
> > Hello,
> > I've got a file with a variable declared in it. For purposes of this
> post:
> >
> > $name = $_POST['name'];
> >
> > Now a little later in the same file I have a custom function call that
> > outputs some information. In that information is an echo statement
> > outputting $name:
> >
> > echo $name;
> >
> > I'm wondering do I have to have $name declared as a global variable
> > within that function? For example:
> >
> > function customFunction() {
> > global $name
> > }
> >
> > I've tried it both ways and both ways it works, with and without the
> > global statement. I was under the impression that to be useful in a
> > function variables outside were not accessible.
> > Thanks.
> > Dave.
>
> Variables declared outside a function are visible outside the function.
> Variables declared inside a function are visible only within that
> function. To use a "global" variable inside a function, you must declare
> it global, as:
>
> global $globalvar;
>
> Paul
>
> --
> Paul M. Foster
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Regards,
Shreyas Agasthya


Re: [PHP] functions and global variables

2010-07-18 Thread Paul M Foster
On Sun, Jul 18, 2010 at 06:37:30PM -0400, David Mehler wrote:

> Hello,
> I've got a file with a variable declared in it. For purposes of this post:
> 
> $name = $_POST['name'];
> 
> Now a little later in the same file I have a custom function call that
> outputs some information. In that information is an echo statement
> outputting $name:
> 
> echo $name;
> 
> I'm wondering do I have to have $name declared as a global variable
> within that function? For example:
> 
> function customFunction() {
> global $name
> }
> 
> I've tried it both ways and both ways it works, with and without the
> global statement. I was under the impression that to be useful in a
> function variables outside were not accessible.
> Thanks.
> Dave.

Variables declared outside a function are visible outside the function.
Variables declared inside a function are visible only within that
function. To use a "global" variable inside a function, you must declare
it global, as:

global $globalvar;

Paul

-- 
Paul M. Foster

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



Re: [PHP] Functions not available when run as Scheduled Task?

2008-02-27 Thread Brian Dunning
Adding this command solved it. Thanks to everyone! I did not even know  
this command existed.



On Feb 27, 2008, at 3:46 PM, Andrés Robinet wrote:


Use the -c command line option to be sure, for example:


C:\php5\php.exe -c "C:\php5\php.ini" -f "D:\wamp\www\scriptname.php"

--


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



Re: [PHP] Functions not available when run as Scheduled Task?

2008-02-27 Thread Jochem Maas

Brian Dunning schreef:
Don't laugh but we have a Win 2003 Server set up with WAMP, and the 
PHP/MySQL scripts work great. I set one up to run as a scheduled task:


C:\php5\php.exe "D:\wamp\www\scriptname.php"

...but nothing happens and the Scheduled Tasks log says that it exited 
with an (ff). So I entered the above manually into a command prompt, and 
it said that mysql_connect() is an unknown function! WTF? It's like it's 
trying to use a different php.ini file that maybe has mysql commented 
out. I double checked that all the php.ini files on the machine do have 
mysql enabled, and anyway mysql works fine normally.


Anyone know what PHP is doing to me here in the scheduled service?


AFAIK php on windows is generally built with all relevant modules included
(check the php.ini used by apaches mod_php and you'll probably notice the
extension=php_mysql.dll line is actually commented out)

my guess would be that the CLI version of php is built without the mysql
extension.

and if it's not that then it's probably down to difference in php.ini after all.





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



RE: [PHP] Functions not available when run as Scheduled Task?

2008-02-27 Thread Andrés Robinet
> -Original Message-
> From: Ray Hauge [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, February 27, 2008 6:42 PM
> To: Brian Dunning
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Functions not available when run as Scheduled Task?
> 
> Brian Dunning wrote:
> > Don't laugh but we have a Win 2003 Server set up with WAMP, and the
> > PHP/MySQL scripts work great. I set one up to run as a scheduled task:
> >
> > C:\php5\php.exe "D:\wamp\www\scriptname.php"
> >
> > ...but nothing happens and the Scheduled Tasks log says that it exited
> > with an (ff). So I entered the above manually into a command prompt, and
> > it said that mysql_connect() is an unknown function! WTF? It's like it's
> > trying to use a different php.ini file that maybe has mysql commented
> > out. I double checked that all the php.ini files on the machine do have
> > mysql enabled, and anyway mysql works fine normally.
> >
> > Anyone know what PHP is doing to me here in the scheduled service?
> >
> 
> I think that there might be a separate php-cli.ini file that is not
> loading the modules that apache does.  I'm too lazy to verify, but I
> remember running into that myself a time or two.  Check the output of
> phpinfo(); or C:\php5\php.exe -v (I think that'll work on Windows).
> 
> --
> Ray Hauge
> www.primateapplications.com
> 
> --

Use the -c command line option to be sure, for example:

C:\php5\php.exe -c "C:\php5\php.ini" -f "D:\wamp\www\scriptname.php"

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



Re: [PHP] Functions not available when run as Scheduled Task?

2008-02-27 Thread Daniel Brown
On Wed, Feb 27, 2008 at 6:37 PM, Brian Dunning <[EMAIL PROTECTED]> wrote:
> Don't laugh but we have a Win 2003 Server set up with WAMP, and the
>  PHP/MySQL scripts work great. I set one up to run as a scheduled task:
>
>  C:\php5\php.exe "D:\wamp\www\scriptname.php"
>
>  ...but nothing happens and the Scheduled Tasks log says that it exited
>  with an (ff). So I entered the above manually into a command prompt,
>  and it said that mysql_connect() is an unknown function! WTF? It's
>  like it's trying to use a different php.ini file that maybe has mysql
>  commented out. I double checked that all the php.ini files on the
>  machine do have mysql enabled, and anyway mysql works fine normally.

Try doing this:



Then run the command:

C:\php5\php.exe D:\wamp\www\phpinfo.php > D:\wamp\www\phpinfo.html

Then view phpinfo.html in a browser.  See how the php.ini and the
MySQL settings are set, and if need be, correct them.  Viewing
phpinfo.php in the browser may show different results.

-- 


Daniel P. Brown
Senior Unix Geek


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



Re: [PHP] Functions not available when run as Scheduled Task?

2008-02-27 Thread Ray Hauge

Brian Dunning wrote:
Don't laugh but we have a Win 2003 Server set up with WAMP, and the 
PHP/MySQL scripts work great. I set one up to run as a scheduled task:


C:\php5\php.exe "D:\wamp\www\scriptname.php"

...but nothing happens and the Scheduled Tasks log says that it exited 
with an (ff). So I entered the above manually into a command prompt, and 
it said that mysql_connect() is an unknown function! WTF? It's like it's 
trying to use a different php.ini file that maybe has mysql commented 
out. I double checked that all the php.ini files on the machine do have 
mysql enabled, and anyway mysql works fine normally.


Anyone know what PHP is doing to me here in the scheduled service?



I think that there might be a separate php-cli.ini file that is not 
loading the modules that apache does.  I'm too lazy to verify, but I 
remember running into that myself a time or two.  Check the output of 
phpinfo(); or C:\php5\php.exe -v (I think that'll work on Windows).


--
Ray Hauge
www.primateapplications.com

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



Re: [PHP] Functions are driving me crazy....

2008-01-25 Thread Jim Lucas

Jason Pruim wrote:

Hi everyone :)

So partly to get an answer, and partly to boost my post rankings for the 
week I have a question.


I am attempting to write an authentication function which would query a 
database, check the username/password and return true if it matches. If 
it doesn't match, then it shouldn't return anything and they are denied 
access.


Here is the code for the function:


function authentication(){

if($user && $pass) { // Keep in mind, PASSWORD has meaning in MySQL
// Do your string sanitizing here
// (e.g. - $user = mysql_real_escape_string($_POST['user']);)
$loginQuery = "SELECT * FROM login WHERE user='".$user."' 
AND Userpass='".$pass."' LIMIT 0,1;";
$loginResult = mysql_query($loginQuery) or die("Wrong data 
supplied or database error"  .mysql_error());

while($row1 = mysql_fetch_array($loginResult)) {
$_SESSION['user'] = $row1['User'];
$_SESSION['loggedin'] = "YES";
$authenticated = "true";
}
}
}return $authenticated;
?>

and here is the code that I am using to call it:

$authenticated = authentication($user, $pass);

but when ever I try and run it I get the following errors in my log 
file, and the page doesn't load the info in the database.


Help me please!



My error log shows this:

[Fri Jan 25 14:55:14 2008] [error] PHP Notice:  Undefined variable: 
authenticated in 
/Volumes/RAIDer/webserver/includes/oldbinc/function/authentication.func.php 
on line 16
[Fri Jan 25 14:55:14 2008] [error] PHP Notice:  Undefined variable: user 
in 
/Volumes/RAIDer/webserver/includes/oldbinc/function/authentication.func.php 
on line 5
[Fri Jan 25 14:55:14 2008] [error] PHP Notice:  Undefined variable: user 
in 
/Volumes/RAIDer/webserver/includes/oldbinc/function/authentication.func.php 
on line 5


--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
[EMAIL PROTECTED]





 0 ) {
  $row = mysql_fetch_assoc($loginResult);
  $_SESSION['user'] = $row1['User'];
  $_SESSION['loggedin'] = "YES";
  $authenticated = "true";
}
  }
  // Make sure your return is inside the closing bracket
  return $authenticated;
}
?>



--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

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



Re: [PHP] Functions are driving me crazy....

2008-01-25 Thread Thijs Lensselink

Nathan Nobbe wrote:
On Jan 25, 2008 3:35 PM, Thijs Lensselink <[EMAIL PROTECTED] 
> wrote:


Change:

}return $authenticated;

to

   return $authenticated;
}

else it will never return the value from the function. But it will
always give you undefined variable notice


nice catch ;)

-nathan


and that on a friday evening :)

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



Re: [PHP] Functions are driving me crazy....

2008-01-25 Thread Nathan Nobbe
On Jan 25, 2008 3:35 PM, Thijs Lensselink <[EMAIL PROTECTED]> wrote:

> Change:
>
> }return $authenticated;
>
> to
>
>return $authenticated;
> }
>
> else it will never return the value from the function. But it will
> always give you undefined variable notice


nice catch ;)

-nathan


Re: [PHP] Functions are driving me crazy....

2008-01-25 Thread Thijs Lensselink

Jason Pruim wrote:

Hi everyone :)

So partly to get an answer, and partly to boost my post rankings for 
the week I have a question.


I am attempting to write an authentication function which would query 
a database, check the username/password and return true if it matches. 
If it doesn't match, then it shouldn't return anything and they are 
denied access.


Here is the code for the function:


function authentication(){
if($user && $pass) { // Keep in mind, PASSWORD has meaning in 
MySQL

// Do your string sanitizing here
// (e.g. - $user = mysql_real_escape_string($_POST['user']);)
$loginQuery = "SELECT * FROM login WHERE user='".$user."' 
AND Userpass='".$pass."' LIMIT 0,1;";
$loginResult = mysql_query($loginQuery) or die("Wrong data 
supplied or database error"  .mysql_error());

while($row1 = mysql_fetch_array($loginResult)) {
$_SESSION['user'] = $row1['User'];
$_SESSION['loggedin'] = "YES";
$authenticated = "true";
}
}
}return $authenticated;
?>

Change:

}return $authenticated;

to

   return $authenticated;
}

else it will never return the value from the function. But it will 
always give you undefined variable notice


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



Re: [PHP] Functions are driving me crazy....

2008-01-25 Thread Richard Lynch


On Fri, January 25, 2008 1:59 pm, Jason Pruim wrote:
> Hi everyone :)
>
> So partly to get an answer, and partly to boost my post rankings for
> the week I have a question.
>
> I am attempting to write an authentication function which would query
> a database, check the username/password and return true if it matches.
> If it doesn't match, then it shouldn't return anything and they are
> denied access.
>
> Here is the code for the function:
>
> 
>   function authentication(){

//initialize the variable so it has SOMETHING in it before you try to
return it at the end:
$authenticated = false;

>   if($user && $pass) { // Keep in mind, PASSWORD has meaning in 
> MySQL

You need to pass in $user and $pass as arguments at the function
authentication ($user, $pass)

>   // Do your string sanitizing here
>   // (e.g. - $user = 
> mysql_real_escape_string($_POST['user']);)
>   $loginQuery = "SELECT * FROM login WHERE 
> user='".$user."' AND
> Userpass='".$pass."' LIMIT 0,1;";
>   $loginResult = mysql_query($loginQuery) or die("Wrong 
> data supplied
> or database error"  .mysql_error());
>   while($row1 = mysql_fetch_array($loginResult)) {
>   $_SESSION['user'] = $row1['User'];
>   $_SESSION['loggedin'] = "YES";
>   $authenticated = "true";
>   }
>   }
>   }return $authenticated;
> ?>
>
> and here is the code that I am using to call it:
>
> $authenticated = authentication($user, $pass);
>
> but when ever I try and run it I get the following errors in my log
> file, and the page doesn't load the info in the database.
>
> Help me please!
>
>
>
> My error log shows this:
>
> [Fri Jan 25 14:55:14 2008] [error] PHP Notice:  Undefined variable:
> authenticated in /Volumes/RAIDer/webserver/includes/oldbinc/function/
> authentication.func.php on line 16
> [Fri Jan 25 14:55:14 2008] [error] PHP Notice:  Undefined variable:
> user in /Volumes/RAIDer/webserver/includes/oldbinc/function/
> authentication.func.php on line 5
> [Fri Jan 25 14:55:14 2008] [error] PHP Notice:  Undefined variable:
> user in /Volumes/RAIDer/webserver/includes/oldbinc/function/
> authentication.func.php on line 5
>
> --
>
> Jason Pruim
> Raoset Inc.
> Technology Manager
> MQC Specialist
> 3251 132nd ave
> Holland, MI, 49424
> www.raoset.com
> [EMAIL PROTECTED]
>
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Functions are driving me crazy....

2008-01-25 Thread Nathan Nobbe
oh; i just noticed you dont have formal parameters for $user or $pass;
so,

function authentication($user, $pass) {
/// ... then you can remove the first line i put in there on the last post
:)
}

-nathan


Re: [PHP] Functions are driving me crazy....

2008-01-25 Thread Nathan Nobbe


-nathan


Re: [PHP] Functions with Static Variables vs. Classes

2007-11-29 Thread Jochem Maas
[EMAIL PROTECTED] wrote:
> From: "Zoltán Németh" <[EMAIL PROTECTED]>
>>>   function example($elem='') {
>>> static $store = array();
>> AFAIK the above line should cause an error on the second run of the
>> function, as you declare the same static variable for the second time.
>>
>> or am I wrong?

indeed you are :-)

> 
> I think so - otherwise static Variables would be quite senseless. The line
> starting with static is (so do I think) once evaluated at compile-time or at
> the first run and the ignored.

I believe it's a compile time definition ... which is the reason you can only
initialize static vars with scalar values (and not the result of expressions or
resources or objects, etc)


> 
> Thomas 
> 

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



Re: [PHP] Functions with Static Variables vs. Classes

2007-11-29 Thread news_yodpeirs
From: "Zoltán Németh" <[EMAIL PROTECTED]>
>>   function example($elem='') {
>> static $store = array();
>
> AFAIK the above line should cause an error on the second run of the
> function, as you declare the same static variable for the second time.
>
> or am I wrong?

I think so - otherwise static Variables would be quite senseless. The line
starting with static is (so do I think) once evaluated at compile-time or at
the first run and the ignored.

Thomas 

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



Re: [PHP] Functions with Static Variables vs. Classes

2007-11-29 Thread Zoltán Németh
2007. 11. 29, csütörtök keltezéssel 14.18-kor [EMAIL PROTECTED]
ezt írta:
> For some simple applications I use a function to collect values in a static
> variable and to return them when called in a special way, just like this
> (fairly senseless) example:
>   function example($elem='') {
> static $store = array();

AFAIK the above line should cause an error on the second run of the
function, as you declare the same static variable for the second time.

or am I wrong?

greets
Zoltán Németh

> if (!func_num_args()) return($store);
> ... do something with $elem ...
> $store[] = $elem;
>   }
> I would call this a singleton-micro-class, as it works like a class with
> data and methods, but there is always only one of it, having only one
> method.
> 
> Why do I? Because I dont need to worry about variablescope as if I would use
> global variables and I dont have to initialize an object before the first
> call (with the scope-problem again). I simply can call it everywhere and
> everytime.
> 
> Do you have any comments to this approach?
> 
> Thomas
> 

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



Re: [PHP] functions versus includes

2007-11-11 Thread Chris

Nathan Nobbe wrote:
On Nov 11, 2007 11:52 PM, Chris <[EMAIL PROTECTED] 
> wrote:


As I said, it's a micro-optimization *shrug*. 0.0004 seconds difference
over 10 iterations - wow ;)


actually it was just one iteration; the output isnt very clear, but 
thats the

value of a variable.
anyway, i was surprised to see the function was faster at all.  i though the
include would be faster.
so not only is the function faster (if only but a bit) its also cleaner 
as well.

i think a decision between the 2 approaches no-brainer.


I'd go for the approach that makes more sense in the application 
regardless of the milliseconds involved. If that's an include that's 
what I'll use.


In the scheme of the whole app it won't make any difference.

You'll waste so much time on "optimizing" crap like this when fixing a 
bad database query will actually make a noticable difference, or instead 
of calling a function inside a loop 50 times, you call it once and pass 
all the data in through an array.


--
Postgresql & php tutorials
http://www.designmagick.com/

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



Re: [PHP] functions versus includes

2007-11-11 Thread Nathan Nobbe
On Nov 11, 2007 11:52 PM, Chris <[EMAIL PROTECTED]> wrote:

> As I said, it's a micro-optimization *shrug*. 0.0004 seconds difference
> over 10 iterations - wow ;)
>

actually it was just one iteration; the output isnt very clear, but thats
the
value of a variable.
anyway, i was surprised to see the function was faster at all.  i though the
include would be faster.
so not only is the function faster (if only but a bit) its also cleaner as
well.
i think a decision between the 2 approaches no-brainer.

-nathan


Re: [PHP] functions versus includes

2007-11-11 Thread Chris

Nathan Nobbe wrote:



On Nov 11, 2007 9:32 PM, Robert Cummings <[EMAIL PROTECTED] 
> wrote:


On Mon, 2007-11-12 at 11:27 +1100, Chris wrote:
 > Frank Lopes wrote:
 > > I just started using PHP and got to think...
 > >
 > > Without getting into the discussion of "best practices",
strictly from
 > > a performance perspective,
 > > what is faster: a function or an include?
 > >
 > > For example I have a block of text that needs to appear
mutliple times
 > > throughout the site.
 > >
 > > Will I be better off creating a function with its contents and then
 > > later just calling the function or,
 > > will it be faster (from an execution perspective) for me to
create an
 > > .inc file that gets included later on?
 >
 > Micro-optimization is pretty useless. I seriously doubt you would
notice
 > any difference in performance.
 >
 > This comes under the other discussions like about which is faster
- a
 > foreach/while/for loop.
 >
 > You'll find other bottlenecks (eg changing a regex to do an
str_replace)
 > which will make a bigger difference.

Actually, if you're going to use a comparison between using regex and
string replacement as an example of lower hanging optimization fruit, I
think you'll find the difference between invoking a function and
including a file to be on par. The function is by far the better
solution when considering speed.


rob is right.  i said screw it and wrote out a series of test scripts; 
just got
curious.  so, there is one file which includes an external script that 
operates
on a variable in global scope; then there is a script which defines a 
function
internally; then there is a script which includes another script with 
that function

defined in it.
the last one won each time; quite to my surprise.

[EMAIL PROTECTED] ~/working/www/phpExperiments/functionVsInclude $ php 
mainWInclude.php

10
totalTime: 0.001057
[EMAIL PROTECTED] ~/working/www/phpExperiments/functionVsInclude $ php 
mainWFunction.php

10
totalTime: 0.000642
[EMAIL PROTECTED] ~/working/www/phpExperiments/functionVsInclude $ php 
mainWExternalFunction.php

10
totalTime: 0.000604


As I said, it's a micro-optimization *shrug*. 0.0004 seconds difference 
over 10 iterations - wow ;)


--
Postgresql & php tutorials
http://www.designmagick.com/

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



Re: [PHP] functions versus includes

2007-11-11 Thread Nathan Nobbe
On Nov 11, 2007 9:32 PM, Robert Cummings <[EMAIL PROTECTED]> wrote:

> On Mon, 2007-11-12 at 11:27 +1100, Chris wrote:
> > Frank Lopes wrote:
> > > I just started using PHP and got to think...
> > >
> > > Without getting into the discussion of "best practices", strictly from
> > > a performance perspective,
> > > what is faster: a function or an include?
> > >
> > > For example I have a block of text that needs to appear mutliple times
> > > throughout the site.
> > >
> > > Will I be better off creating a function with its contents and then
> > > later just calling the function or,
> > > will it be faster (from an execution perspective) for me to create an
> > > .inc file that gets included later on?
> >
> > Micro-optimization is pretty useless. I seriously doubt you would notice
> > any difference in performance.
> >
> > This comes under the other discussions like about which is faster - a
> > foreach/while/for loop.
> >
> > You'll find other bottlenecks (eg changing a regex to do an str_replace)
> > which will make a bigger difference.
>
> Actually, if you're going to use a comparison between using regex and
> string replacement as an example of lower hanging optimization fruit, I
> think you'll find the difference between invoking a function and
> including a file to be on par. The function is by far the better
> solution when considering speed.
>

rob is right.  i said screw it and wrote out a series of test scripts; just
got
curious.  so, there is one file which includes an external script that
operates
on a variable in global scope; then there is a script which defines a
function
internally; then there is a script which includes another script with that
function
defined in it.
the last one won each time; quite to my surprise.

[EMAIL PROTECTED] ~/working/www/phpExperiments/functionVsInclude $ php
mainWInclude.php
10
totalTime: 0.001057
[EMAIL PROTECTED] ~/working/www/phpExperiments/functionVsInclude $ php
mainWFunction.php
10
totalTime: 0.000642
[EMAIL PROTECTED] ~/working/www/phpExperiments/functionVsInclude $ php
mainWExternalFunction.php
10
totalTime: 0.000604


ill show the code if anyone wants it.

-nathan


Re: [PHP] functions versus includes

2007-11-11 Thread Robert Cummings
On Mon, 2007-11-12 at 11:27 +1100, Chris wrote:
> Frank Lopes wrote:
> > I just started using PHP and got to think...
> > 
> > Without getting into the discussion of "best practices", strictly from  
> > a performance perspective,
> > what is faster: a function or an include?
> > 
> > For example I have a block of text that needs to appear mutliple times 
> > throughout the site.
> > 
> > Will I be better off creating a function with its contents and then 
> > later just calling the function or,
> > will it be faster (from an execution perspective) for me to create an 
> > .inc file that gets included later on?
> 
> Micro-optimization is pretty useless. I seriously doubt you would notice 
> any difference in performance.
> 
> This comes under the other discussions like about which is faster - a 
> foreach/while/for loop.
> 
> You'll find other bottlenecks (eg changing a regex to do an str_replace) 
> which will make a bigger difference.

Actually, if you're going to use a comparison between using regex and
string replacement as an example of lower hanging optimization fruit, I
think you'll find the difference between invoking a function and
including a file to be on par. The function is by far the better
solution when considering speed.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

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



Re: [PHP] functions versus includes

2007-11-11 Thread Chris

Frank Lopes wrote:

I just started using PHP and got to think...

Without getting into the discussion of "best practices", strictly from  
a performance perspective,

what is faster: a function or an include?

For example I have a block of text that needs to appear mutliple times 
throughout the site.


Will I be better off creating a function with its contents and then 
later just calling the function or,
will it be faster (from an execution perspective) for me to create an 
.inc file that gets included later on?


Micro-optimization is pretty useless. I seriously doubt you would notice 
any difference in performance.


This comes under the other discussions like about which is faster - a 
foreach/while/for loop.


You'll find other bottlenecks (eg changing a regex to do an str_replace) 
which will make a bigger difference.


--
Postgresql & php tutorials
http://www.designmagick.com/

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



Re: [PHP] functions for sorting/paging functionality for imap mailboxes

2007-07-02 Thread Greg Donald

On 6/25/07, Yashesh Bhatia <[EMAIL PROTECTED]> wrote:

  i'm implementing an imap based mail client


That's a major wheel to go reinventing, have you not tried IMP/Horde?

http://www.horde.org/imp/


--
Greg Donald
http://destiney.com/

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



Re: [PHP] functions classes

2006-08-26 Thread Alex Turner

Larry,

I have hit similar global names space issues in the past and it is a 
pain in the behind!


One remedial method that can get it stable enough to start to work on is 
to stick the whole messy lot into classes (NOT OBJECTS!) and then the 
global name space becomes the local namespace (ie $MyVar becomes 
$GarbageCode::MyVar).


Once you have done this, you can put accessors functions around the 
class local variables.  This means that all new code calls the accessors.


$newVar=GarbageCode::GetMyVar();

Thus, if you improve the internal representation of the garbage code, 
code outside the old garbage code will no longer be impacted by the change.


From an FN point of view, you are reducing the access to the variable 
to a single function point rather than many function points distributed 
throughout the code base.


Cheers

AJ

PS - if you knew all this before hand - please accept my apologies :-)

Larry Garfield wrote:

On Friday 25 August 2006 04:39, Bigmark wrote:

Can anyone tell me if it is relatively an easy process for an experienced
coder (not me) to convert a php script to mainly functions/classes.
I have my own script that i would like to make more streamlined as it is
becoming very difficult to work with.


That really depends on the nature of the code.  I've some code I have to work 
with now that is built around dumping all kinds of stuff into the global 
namespace, even from functions.  If I ever manage convince the author what an 
insanely bad idea that is, it will still be hell to fix because of the way 
it's built.


Most code probably isn't quite that bad, though.  Your code could already 
break down into functions quite nicely, or it could be easier to just start 
from scratch.  No way to tell without seeing the code.





--
www.deployview.com
www.nerds-central.com
www.project-network.com

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



Re: [PHP] functions classes

2006-08-25 Thread Larry Garfield
On Friday 25 August 2006 04:39, Bigmark wrote:
> Can anyone tell me if it is relatively an easy process for an experienced
> coder (not me) to convert a php script to mainly functions/classes.
> I have my own script that i would like to make more streamlined as it is
> becoming very difficult to work with.

That really depends on the nature of the code.  I've some code I have to work 
with now that is built around dumping all kinds of stuff into the global 
namespace, even from functions.  If I ever manage convince the author what an 
insanely bad idea that is, it will still be hell to fix because of the way 
it's built.

Most code probably isn't quite that bad, though.  Your code could already 
break down into functions quite nicely, or it could be easier to just start 
from scratch.  No way to tell without seeing the code.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

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



Re: [PHP] functions classes

2006-08-25 Thread Dave Goodchild

On 25/08/06, Peter Lauri <[EMAIL PROTECTED]> wrote:


It should not be to big of a problem if you can set your mind into
thinking
about functions and objects instead of a step by step script. Then just
cut
it in pieces and your are done :)



Agreed. If it puts you on the good foot, send an extract from your script
and I will give you an indicator of where to start.




--
http://www.web-buddha.co.uk
http://www.projectkarma.co.uk


RE: [PHP] functions classes

2006-08-25 Thread Peter Lauri
It should not be to big of a problem if you can set your mind into thinking
about functions and objects instead of a step by step script. Then just cut
it in pieces and your are done :)

-Original Message-
From: Bigmark [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 25, 2006 4:40 PM
To: php-general@lists.php.net
Subject: [PHP] functions classes

Can anyone tell me if it is relatively an easy process for an experienced
coder (not me) to convert a php script to mainly functions/classes.
I have my own script that i would like to make more streamlined as it is
becoming very difficult to work with.

-- 
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



Re: [PHP] Functions

2006-08-14 Thread Richard Lynch
On Sun, August 13, 2006 8:45 pm, Gerry D wrote:
> On 6/30/06, Richard Lynch <[EMAIL PROTECTED]> wrote:
>
>> #2. Don't alter the case of the input data, if at all possible.
>> Accept what the user has given, and take it as it is.  You can make
>> your application not care about case, and you can format the case on
>> ouput (maybe even with fancy CSS stuff) but don't mess with their
>> input.
>
> Why not clean up crappy input right at the source, Richard?

Clean up crappy input, of course.

Convert perfectly-valid NEWLINE into a tag  for browser output, no.

The conversion of the data for OUTPUT to a specific medium (browser,
RSS, XML, WAP, FUTURE TECH #1*) should be done on OUTPUT, not INPUT.

Othewise, to convert your input plain -> HTML data to WAP, you first
have to UNDO the plain -> HTML conversion, then do a plain -> WAP
conversion.

That's just daft.

* You should get a warm fuzzy for recognizing this phrase. :-)

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] Functions

2006-08-13 Thread Gerry D

On 6/30/06, Richard Lynch <[EMAIL PROTECTED]> wrote:


#2. Don't alter the case of the input data, if at all possible.
Accept what the user has given, and take it as it is.  You can make
your application not care about case, and you can format the case on
ouput (maybe even with fancy CSS stuff) but don't mess with their
input.


Why not clean up crappy input right at the source, Richard?

Gerry

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



Re: [PHP] Functions

2006-07-13 Thread Amit Arora

Hi,

You might wanna try something like this:

function cleaner($var)
{
$var = trim($var);
$var = strip_tags($var);
$var = ucfirst($var);
$var = addslashes($var);
// This line is not required $var = str_replace ("$","",$var);
return ($var)
}

And to actually use this function you will have to use something like this.

$var = cleaner($var);

Regards,

Amit Arora
www.digitalamit.com

[EMAIL PROTECTED] wrote:
I was able to get the return to work but not the pass in the reference.  
One

last question, what if I want to have each item on a separate line like:

function cleaner($var)
{
trim($var);
strip_tags($var);
ucfirst($var);
addslashes($var);
str_replace ("$","",$var);
}

$var = "abc's";
echo $var;

How would I return the results here, I tried various different ways none of
them worked?



On 6/29/06, Chris <[EMAIL PROTECTED]> wrote:


[EMAIL PROTECTED] wrote:
> I am trying to create a function to clean up variables that are user
> inputted from a form.  I am not getting this script to work.  Can 
anyone

> help.
>
> ---Start Script---
> function cleaner($var)
> {
> trim(strip_tags(ucfirst(addslashes($var;
> }
>
> $var = "abc's";
>
> echo $var;


You need to return the value from the function:

return trim(strip_tags(.)

or pass in a reference:

function cleaner (&$var)


--
Postgresql & php tutorials
http://www.designmagick.com/







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



Re: [PHP] Functions

2006-06-30 Thread Stut

[EMAIL PROTECTED] wrote:
I was able to get the return to work but not the pass in the reference.  
One

last question, what if I want to have each item on a separate line like:

function cleaner($var)
{
trim($var);
strip_tags($var);
ucfirst($var);
addslashes($var);
str_replace ("$","",$var);
}

$var = "abc's";
echo $var;

How would I return the results here, I tried various different ways none of
them worked?


From your code snippet there are clearly too many fundamentals that you 
don't seem to understand. I suggest you Google for a PHP beginners 
tutorial, read it and then start again. You may have better luck after 
you understand how PHP works. You may also want to look in the PHP 
manual for the documentation for the functions you are using above, and 
also at the section on functions. Everything you need is there - absorb it.


-Stut

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



Re: [PHP] Functions

2006-06-30 Thread Richard Lynch
On Fri, June 30, 2006 12:00 am, [EMAIL PROTECTED] wrote:
> I am trying to create a function to clean up variables that are user
> inputted from a form.  I am not getting this script to work.  Can
> anyone
> help.
>
> ---Start Script---
> function cleaner($var)
> {
> trim(strip_tags(ucfirst(addslashes($var;
> }
>
> $var = "abc's";
>
> echo $var;
> ---End Script---
>
> When I run the above script it produces nothing. Instead of a result
> of
> "Abc\'s".

At the simplistic level, the problem is that you are not using
"return" to actually RETURN the answer, so you do all that work and
throw away the result.

return trim(strip_tags(ucfirst(addslashes($var;


At a higher level, the problem is that you are basically doing several
things very very very wrong here...

#1. addslashes should be replaced with the database-specific escaper,
such as mysql_real_escape_string, or you should use prepared
statements so that the DB cannot possibly mistake data for SQL.

#2. Don't alter the case of the input data, if at all possible. 
Accept what the user has given, and take it as it is.  You can make
your application not care about case, and you can format the case on
ouput (maybe even with fancy CSS stuff) but don't mess with their
input.

#3. strip_tags should probably happen first...  Otherwise the escaping
of the data going into the DB could, possibly, be defeated by clever
arrangement of HTML tags that disguise the invalid data.

#4. There is a complete lack of actual validation here...  You'd be
WAY better off to make sure the incoming data is what you expect, and
not accept bad input, than to just blindly strip_tags on it.

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] Functions

2006-06-30 Thread [EMAIL PROTECTED]

I was able to get the return to work but not the pass in the reference.  One
last question, what if I want to have each item on a separate line like:

function cleaner($var)
{
trim($var);
strip_tags($var);
ucfirst($var);
addslashes($var);
str_replace ("$","",$var);
}

$var = "abc's";
echo $var;

How would I return the results here, I tried various different ways none of
them worked?



On 6/29/06, Chris <[EMAIL PROTECTED]> wrote:


[EMAIL PROTECTED] wrote:
> I am trying to create a function to clean up variables that are user
> inputted from a form.  I am not getting this script to work.  Can anyone
> help.
>
> ---Start Script---
> function cleaner($var)
> {
> trim(strip_tags(ucfirst(addslashes($var;
> }
>
> $var = "abc's";
>
> echo $var;


You need to return the value from the function:

return trim(strip_tags(.)

or pass in a reference:

function cleaner (&$var)


--
Postgresql & php tutorials
http://www.designmagick.com/





--
**
The content of this e-mail message and any attachments are confidential and
may be legally privileged, intended solely for the addressee. If you are not
the intended recipient, be advised that any use, dissemination,
distribution, or copying of this e-mail is strictly prohibited. If you
receive this message in error, please notify the sender immediately by reply
email and destroy the message and its attachments.
*


Re: [PHP] Functions

2006-06-29 Thread Chris

[EMAIL PROTECTED] wrote:

I am trying to create a function to clean up variables that are user
inputted from a form.  I am not getting this script to work.  Can anyone
help.

---Start Script---
function cleaner($var)
{
trim(strip_tags(ucfirst(addslashes($var;
}

$var = "abc's";

echo $var;



You need to return the value from the function:

return trim(strip_tags(.)

or pass in a reference:

function cleaner (&$var)


--
Postgresql & php tutorials
http://www.designmagick.com/

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



Re: [PHP] Functions

2006-06-29 Thread John Meyer

Two things:
1.  You're not returning anything from the function.
2.  You're not even using the function.

[EMAIL PROTECTED] wrote:

I am trying to create a function to clean up variables that are user
inputted from a form.  I am not getting this script to work.  Can anyone
help.

---Start Script---
function cleaner($var)
{
trim(strip_tags(ucfirst(addslashes($var;
}

$var = "abc's";

echo $var;
---End Script---

When I run the above script it produces nothing. Instead of a result of
"Abc\'s".




--
Online library -- http://pueblonative.110mb.com
138 books and counting.

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



Re: [PHP] functions that take variable arguments?

2005-12-05 Thread Richard Heyes

Eternity Records Webmaster wrote:

how do you create/use a function that takes an undefined amount of
arguments? I looked at the manual but its a little confusing. for example, i
want to make a function called Update inside a DB class:

class DB {
//vars here
var $host;
var $DbUser;

//functions
function Update(...) {
//this function can take as few as 1 argument or as many as php will allow
//its supposed to update a database with the new values of the arguments.
//any help getting started on creating a function like this would be
apreciated
}
//end class
}



class DB
{
function Update()
{
$args = func_get_args();
}
}

$args will then be a regular array of any/all the arguments passed to 
the function.


--
Richard Heyes
http://www.phpguru.org/

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



Re: [PHP] Functions Returning large strings

2005-09-29 Thread Andy Pieters
Hi
> I have a series of nested functions which return a large string (as apposed
> to working on global string) , is this inefficient? Or is PHP clever enough
> to just pass a pointer?

> $large_string=fn_one(fn_two(fn_three(;

PHP is by no means cleaver enough to read your mind as to what you want it to 
do.

If you want to pass pointers instead of strings then do as this

function one(&$buffer)
{
 #processing, return true/false based on success, put result in buffer
}

function two(&$buffer)
{
 #processing,...
}

Then do like this:

$variable='input value';
if(one($variable))
 if(two($variable))
 echo "Result: $variable";

HTH

Andy

-- 
Registered Linux User Number 379093
Now listening to [silence]

   amaroK::the Coolest Media Player in the known Universe!


   Cockroaches and socialites are the only things that can 
   stay up all night and eat anything.
Herb Caen
--
-- --BEGIN GEEK CODE BLOCK-
Version: 3.1
GAT/O/>E$ d-(---)>+ s:(+)>: a--(-)>? C$(+++) UL>$ P-(+)>++
L+++>$ E---(-)@ W+++>+++$ !N@ o? !K? W--(---) !O !M- V-- PS++(+++)
PE--(-) Y+ PGP++(+++) t+(++) 5-- X++ R*(+)@ !tv b-() DI(+) D+(+++) G(+)
e>$@ h++(*) r-->++ y--()>
-- ---END GEEK CODE BLOCK--
--
Check out these few php utilities that I released
 under the GPL2 and that are meant for use with a 
 php cli binary:
 
 http://www.vlaamse-kern.com/sas/

--


pgphHcBjoE1mU.pgp
Description: PGP signature


Re: [PHP] functions vs classes

2005-04-04 Thread Martin . C . Austin
I know I sure appreciate reading any discussions on OOP issues, as they 
are something I just cannot seem to grasp.

Thanks!

Martin Austin





Brent Baisley <[EMAIL PROTECTED]>
04/04/2005 08:44 AM
 
To: DuSTiN KRySaK <[EMAIL PROTECTED]>
cc: PHP 
Subject:        Re: [PHP] functions vs classes


At the most basic level a class allows you to group your functions 
together. On small projects, grouping of functions may not seem to buy 
you anything. But the bigger the project gets, the more you would like 
to be able to keep your functions separated into groups.

One simple advantage of classes is that they prevent naming conflicts 
with your functions. This is very important when you are sharing code 
since you don't know what another programmer named their functions. 
What if you both name a function "get_one_record"? If you use classes, 
you only need to keep the names of your classes unique. Which then 
means you can use the same generic function name across all your 
classes, and you interface within your classes in a consistent manner, 
only the context changes.

For instance, you may have a class call "companies" and another called 
"contacts". Within each you may have functions called "get_list", 
"get_one" and "delete_one". Same function names, but in different 
classes so they don't conflict. Now you could create a generic 
interface to view a list, view a record or delete a record. What data 
is displayed depends on which class you load. The function names are 
all the same, so you don't need to change your code when you change the 
context (companies or contacts).

This is hardly a tutorial on OOP. But maybe it will give you an idea of 
the benefits of using classes.


On Apr 4, 2005, at 12:28 AM, DuSTiN KRySaK wrote:

> Novice PHPer, and i am wondering why one would use a function instead 
> of a class (or object)? They seem to server very similar in use.
>
> The way I see it, is a function if for repeated use in a project 
> specific manner, where as a class could be used for many projects.
>
> is this correct?
>
> Although one could just include the function library in multiple 
> projects.
>
> Thanks!
>
> Dustin
>
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
-- 
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577

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




Re: [PHP] functions vs classes

2005-04-04 Thread Brent Baisley
At the most basic level a class allows you to group your functions 
together. On small projects, grouping of functions may not seem to buy 
you anything. But the bigger the project gets, the more you would like 
to be able to keep your functions separated into groups.

One simple advantage of classes is that they prevent naming conflicts 
with your functions. This is very important when you are sharing code 
since you don't know what another programmer named their functions. 
What if you both name a function "get_one_record"? If you use classes, 
you only need to keep the names of your classes unique. Which then 
means you can use the same generic function name across all your 
classes, and you interface within your classes in a consistent manner, 
only the context changes.

For instance, you may have a class call "companies" and another called 
"contacts". Within each you may have functions called "get_list", 
"get_one" and "delete_one". Same function names, but in different 
classes so they don't conflict. Now you could create a generic 
interface to view a list, view a record or delete a record. What data 
is displayed depends on which class you load. The function names are 
all the same, so you don't need to change your code when you change the 
context (companies or contacts).

This is hardly a tutorial on OOP. But maybe it will give you an idea of 
the benefits of using classes.

On Apr 4, 2005, at 12:28 AM, DuSTiN KRySaK wrote:
Novice PHPer, and i am wondering why one would use a function instead 
of a class (or object)? They seem to server very similar in use.

The way I see it, is a function if for repeated use in a project 
specific manner, where as a class could be used for many projects.

is this correct?
Although one could just include the function library in multiple 
projects.

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

--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] functions vs classes

2005-04-03 Thread Domas Juknevicius / DEFORM GROUP
Hello,

Quite good and short answer to your question:
http://answers.google.com/answers/threadview?id=207071

--
Domas Juknevicius

DuSTiN KRySaK wrote:
> Novice PHPer, and i am wondering why one would use a function instead of
> a class (or object)? They seem to server very similar in use.
> 
> The way I see it, is a function if for repeated use in a project
> specific manner, where as a class could be used for many projects.
> 
> is this correct?
> 
> Although one could just include the function library in multiple projects.
> 
> Thanks!
> 
> Dustin
> 

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



Re: [PHP] functions vs classes

2005-04-03 Thread Lars B. Jensen
Novice PHPer, and i am wondering why one would use a function instead of a 
class (or object)? They seem to server very similar in use.
All depends on the specific use and situation - pros and cons by both 
models, for speed and performance, I mostly use optimized functions sorted 
out in structured files for easy reuse, rather than objects. PHP5 seem to 
embrase object orientation more, so lets see if a war starts again - it's 
religion. Think before you program.

The way I see it, is a function if for repeated use in a project specific 
manner, where as a class could be used for many projects.
It's precisely the same, if you include a file with your class or include a 
file with your functions, whats the difference ? none.

--
Lars B. Jensen, Internet Architect
CareerCross Japan
Japan's premier online career resource for english speaking professionals
http://www.careercross.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] functions and session variables

2004-02-18 Thread Vail, Warren
the $_SESSION array is available everywhere.  I seem to be able to access it
within a function without declaring it as a global.  It is customary to
declare globals that you intend to access in a function (almost everything
undeclared is assumed to be local to the function).  Other exceptions that I
know about like the session array are; $_GET, $_POST, and $GLOBALS, and
there could be others.

Even with the "register globals" PHP option turned on (this will cause all
$_GET, $_POST, and $_SESSION variables to be defined automatically before
you execute, I believe you still need to declare the globals you intend to
use in a function, so accessing things from anywhere, for the most part is
not directly available (I can't recall a time when it ever was), with the
exceptions mentioned above.

I personally like the way PHP does things just fine,

Warren Vail


-Original Message-
From: craig [mailto:[EMAIL PROTECTED]
Sent: Wednesday, February 18, 2004 3:08 PM
To: Php
Subject: [PHP] functions and session variables


Hi,
I just want to verify something that seems counterintuitive
to me. Do you have to pass session variables to functions?
It would seem to me that they should be available anywhere.

I took a cursory look through the manual, but didn't see
anything relevant.

Thanks,
Craig

-- 
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



RE: [PHP] functions/methods and what they should return

2003-08-20 Thread Dan Anderson
While I'm still on my soapbox...

There are a number of great books out there on object oriented
programming.  Basically the idea is to take a top down approach --
decide what components makes up what you want to do, what components
make up those components, and so on until you can program common
components together instead of having that much more code to modify.  

And this is a /great/ way to tackle large projects.  I have some
scripts where I use a 400 line function a dozen times.  Much easier to
modify 400 lines when needed instead of 4800!  

But at the same time, for quick and dirty projects it's not efficient. 
If all you need is a quick 100 line script you'd be bloating your code
to use the OOP approach.  The simple fact is that when you try to write
a function you have to create variables and other things to make it much
more general -- and that can be a lot harder then just /doing it/. 
Plus, on a quick script it may become silly to break down things into
components unless you plan on expanding on the script at some point in
the future...

-Dan

On Wed, 2003-08-20 at 22:31, Chris W. Parker wrote:
> Dan and Ray,
> 
> Thanks for your help. This helps clear some things up for me!
> 
> 
> Chris.


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



RE: [PHP] functions/methods and what they should return

2003-08-20 Thread Chris W. Parker
Dan and Ray,

Thanks for your help. This helps clear some things up for me!


Chris.

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



RE: [PHP] functions/methods and what they should return

2003-08-20 Thread Ray Hunter

> function GetAttributes($id)
> {
>   // query db
> 
>   // get records
> 
>   // return record array
> }
> 
> function BuildAttributes($id)
> {
>   $attributes = GetAttributes($id);
> 
>   // format $attributes
> 
>   // return HTML string
> }


That is a good way...you have the functions only doing what they need to
do. Thus splitting up some of the logic and presentation. In the
GetAttributes function you could do any filtering...but mainly you dont
want to do any presentation because u can now reuse that function other
places.

--
BigDog


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



RE: [PHP] functions/methods and what they should return

2003-08-20 Thread Dan Anderson
> Hmm.. Although this sounds like a good idea at first, it seems like it
> would get pretty complicated really fast. Am I missing something?

Well the idea is that on very large programs you create a number of
different components that can be used and changed independently.  To
give you an example, if you don't split up those two functions, and you
decide you want to modify the way the results are displayed, it is
possible you could accidentally "break" the database query when updating
the way tables are updated.  (i.e. debugging is easier because you can
test functions in seperate programs.

The other thing is (again, on very large programs.  for small programs
the quick and dirty solution is almost always faster) that if, for
instance, you decided you wanted to create a second way to display
results you could either cut and paste the original big function and
modify it or create two functions that call GetAttributes.

But if you cut and paste, when you go to change the way GetAttributes
gets attributes you will need to update /two/ functions and not just
one.  This is one of the reasons why breaking things up into components
makes creating and maintaining very large scripts easier.

-Dan


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



RE: [PHP] functions/methods and what they should return

2003-08-20 Thread Chris W. Parker
Dan Anderson 
on Wednesday, August 20, 2003 3:04 PM said:

> You want to break off things into as many functions and components as
> possible.

Hmm.. Ok. So right now I've got this (psuedo code):

function displayAttributes($id)
{
// query db
// store results in array

// perform logic that builds HTML string

// return HTML string
}

But instead you think I should do this:

function GetAttributes($id)
{
// query db

// get records

// return record array
}

function BuildAttributes($id)
{
$attributes = GetAttributes($id);

// format $attributes

// return HTML string
}

Is that what you're suggesting?

> The idea is that if you want to change the way tables are
> displayed with the data, for instance, you can't break the way data is
> queried.

I don't understand this exactly. What do you mean by "can't break the
way data is queried"?

> I usually have a bunch of different files like
> "inc.function.something.php" and use lots of require_once()
> statements. 

Hmm.. Although this sounds like a good idea at first, it seems like it
would get pretty complicated really fast. Am I missing something?


Thanks.
Chris.

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



Re: [PHP] functions/methods and what they should return

2003-08-20 Thread Ray Hunter

> Each product that is in the database can have at least one attribute to
> it (i.e. color, size, etc.). Right now I've got a method in my Products
> class called ShowAttributes($id). This method, based on the ID passed to
> it, will query the db and ultimately return a string that makes up the
> drop down box for a form.
> 
> Am I better off doing this sort of thing in a function or having the
> function only return the records I need and let the calling page handle
> the display of the records?

I usually allow the function get only what i need, thus making it as
simple as i possibly can. If you are using it as a drop down function
for a form then i would get the data form a generic source and populate
it with that information (i.e. i use arrays that hold data for forms,
and query the database to find out which item in the dropdown should be
selected. 

So in short:
1. Have a function return only what you need (meaning that it should be
in the right format for you.)
2. Have the display page handle all the dropdown logic.


--
BigDog


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



Re: [PHP] functions/methods and what they should return

2003-08-20 Thread Dan Anderson
You want to break off things into as many functions and components as
possible.  The idea is that if you want to change the way tables are
displayed with the data, for instance, you can't break the way data is
queried.  I usually have a bunch of different files like
"inc.function.something.php" and use lots of require_once() statements.

-Dan

On Wed, 2003-08-20 at 21:59, Chris W. Parker wrote:
> Hi people.
> 
> I'm working on a large application right now (complete ecom store) and
> I'd like to get some feedback on something.
> 
> Each product that is in the database can have at least one attribute to
> it (i.e. color, size, etc.). Right now I've got a method in my Products
> class called ShowAttributes($id). This method, based on the ID passed to
> it, will query the db and ultimately return a string that makes up the
> drop down box for a form.
> 
> Am I better off doing this sort of thing in a function or having the
> function only return the records I need and let the calling page handle
> the display of the records?
> 
> 
> What do you think about this?
> 
> 
> Thanks,
> Chris.


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



Re: [PHP] Functions in Safe Mode?

2003-08-04 Thread Jason Sheets
The problem is the owner of the script must be the owner of the file 
that you are accessing.  If you fix your file ownership for your news 
directory or change your php script to be the same owner as the news 
directoryo you will be able to access the files.

Look at the chown command,. you will need to execute it on the command line.

Jason

Jay Fitzgerald wrote:

My code: echo number_format(filesize("news/final_1.txt"));
The Warning: Warning: filesize() [
 function.filesize]: SAFE MODE
Restriction in effect. The script whose uid is 17704 is not allowed to
access news/final_1.txt owned by uid 65534 in
/home/***/public_html/news.php on line 10
0
The Question: Is there a way to get the file size of files if safe mode
is on? I need to do an IF/ELSE statement so that if the file size is
less than a certain size, then it does not display the text contained in
that file. Am I going about this the wrong way?


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


Re: [PHP] functions, opinion...

2003-06-17 Thread Hugh Bothwell
"Dvdmandt" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> Now, where did those two paragraphs come from? A bit of experience with
all
> those langs and the BASIC school... I'm at the age of 14 and don't even
know
> math yet so (I mean, I know +, -, / and *, but not advanced stuff)...


"functional programming" is based around the idea
that subroutines should have no side effects - all
the information a subroutine needs should be passed
as parameters, and its results should be returned.
Further, a function called with the same set of parameters
should always return the same result.

The original basis for this was that it made
program analysis much simpler; however, it
was found to be useful in practice as well for
a number of reasons:

- it was a means of enforcing variable scope
  (essentially, all variables are local),

- it promotes much simpler functions and
  more reuse.

- it can allow much more extreme compiler
  optimizations


While the functional programming philosophy
can be applied in most programming languages,
some of the languages I mentioned do a better
job of making its usefulness obvious.

For more info, see some of the links at
http://directory.google.com/Top/Computers/Programming/Languages/Functional/


--
Hugh Bothwell [EMAIL PROTECTED] Kingston ON Canada
v3.1 GCS/E/AT d- s+: a- C+++ L++>+++$ P+ E- W+++$ N++ K? w++ M PS+
PE++ Y+ PGP+ t-- 5++ !X R+ tv b DI+++ D-(++) G+ e(++) h-- r- y+




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



RE: [PHP] functions, opinion...

2003-06-17 Thread Dan Joseph
Hi,

> Depends on the use of the function. (Output functions should produce
> output shouldn't they?!) Best option probably is to specifiy an argument
> that allows to choose wether to output or to return.
> If you return text you should return by reference to prevent unnecessary
> memory consumption.

Recently, I have been doing more of returning than echoing from inside a
function.  I found it more useful I guess.

Seems the general consensus is to simply keep the echoing from the
functions most of the time, and in some minor cases, use it.  To me, this
makes sense.

Thanks all for your opinions.

-Dan Joseph


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



RE: [PHP] functions, opinion...

2003-06-17 Thread Dan Joseph
Hi,

> > My personal opinion, which shows in all my code writing is to
> never echo
> > inside a function. always return the data whether it be string, array,
> > or boolean... I've always left echoing up to the actual page
> showing the
> > data. That way if you have two seperate pages that need to display the
> > data differently, you can use the same function, and just format it as
> > needed on the pages.

This is kind of what I thought would be the majority of the responses.
I've found that since the inception of web languages (ASP, PHP, etc) that
I've "abused" functions a bit.  I then got to thinking one day that maybe
what I was doing was normal, but then I figured that it probably wasn't.  At
times it seems like it caused me to scramble all my logic.

-Dan Joseph


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



Re: [PHP] functions, opinion...

2003-06-17 Thread Lars Torben Wilson
On Mon, 2003-06-16 at 23:20, Jason Wong wrote:
> On Tuesday 17 June 2003 12:50, DvDmanDT wrote:
> > I was replying to "If you don't do it this way, you'll
> > find yourself re-writing a function sooner or later because you need it
> > to return the data instead of displaying it."... Then you don't need to
> > modify the function if you turn on ob, call function, then get contents,
> > then clear ob... Ok, it's a rather bad way to do it, but it works for me...
> 
> Even the php crew had to rewrite functions because it displayed data instead 
> of returning. Case in point: print_r() recently had a extra argument added to 
> specify whether the output was printed or returned.

I agree with your point, but the adding of the second argument was more
of a convenience thing than an admission that printing when calling a
print statement was bad behaviour. :) Besides, it's more consistent
since the introduction of var_export() with its similar abilities.

As to your actual point (no more hair splitting): I agree. If the
function has something to say, it's better to store that somehow and
then use it when you need it. You get to determine when (and if) it
gets output, and how. As someone else noted, you will sometimes find it
necessary to break this rule (quick debugging statements, or functions
whose purpose is to actually output something), but in general I
wouldn't expect to see any benefit to having your functions doing their
own output--beyond the initial convenience. For one thing, it can make
effective use of templates a bloody pain.


Just some thoughts,

Torben


-- 
 Torben Wilson <[EMAIL PROTECTED]>+1.604.709.0506
 http://www.thebuttlesschaps.com  http://www.inflatableeye.com
 http://www.hybrid17.com  http://www.themainonmain.com
 - Boycott Starbucks!  http://www.haidabuckscafe.com -




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



Re: [PHP] functions, opinion...

2003-06-17 Thread SLanger
Depends on the use of the function. (Output functions should produce 
output shouldn't they?!) Best option probably is to specifiy an argument 
that allows to choose wether to output or to return.
If you return text you should return by reference to prevent unnecessary 
memory consumption. 


Regards
Stefan Langer

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



Re: [PHP] functions, opinion...

2003-06-16 Thread Jason Wong
On Tuesday 17 June 2003 12:50, DvDmanDT wrote:
> I was replying to "If you don't do it this way, you'll
> find yourself re-writing a function sooner or later because you need it
> to return the data instead of displaying it."... Then you don't need to
> modify the function if you turn on ob, call function, then get contents,
> then clear ob... Ok, it's a rather bad way to do it, but it works for me...

Even the php crew had to rewrite functions because it displayed data instead 
of returning. Case in point: print_r() recently had a extra argument added to 
specify whether the output was printed or returned.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
I have learned silence from the talkative,
toleration from the intolerant, and kindness from the unkind.
-- Kahlil Gibran
*/


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



Re: [PHP] functions, opinion...

2003-06-16 Thread DvDmanDT
I was replying to "If you don't do it this way, you'll
find yourself re-writing a function sooner or later because you need it
to return the data instead of displaying it."... Then you don't need to
modify the function if you turn on ob, call function, then get contents,
then clear ob... Ok, it's a rather bad way to do it, but it works for me...
Problem comes if ob is already on though... The question is definitly a
matter of situation... In a template system, all output should be
returned... For an error function, maybe the error should be displayed... I
use functions to add header and footer on some of my pages... Now, I guess
that could be returned as well, but why type "echo mk_body()" when you could
just type mk_body()..?

Now, where did those two paragraphs come from? A bit of experience with all
those langs and the BASIC school... I'm at the age of 14 and don't even know
math yet so (I mean, I know +, -, / and *, but not advanced stuff)...

// DvDmanDT
"Hugh Bothwell" <[EMAIL PROTECTED]> skrev i meddelandet
news:[EMAIL PROTECTED]
> "Dvdmandt" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Or you could just temporarily enable ob... That's what I do when I have
a
> > function that needs to return lots of HTML containing many ' and "... I
> know
> > it's possible to use \ as well, but ob is somewhat easier then...
>
>
> You're missing the point.  Output buffering can be useful,
> but it is an entirely separate issue from the functional
> programming style these two are endorsing
> (and with which I wholeheartedly agree).
>
> Too many people learned programming in the
> BASIC school, writing 'do this, then add this, then
> append that and the other' programs and ending
> up with five-page subroutines.
>
> A bit of experience with LISP or ML or FORTH
> can be a wonderful thing; you start to see how
> to simplify your problems, breaking them into
> smaller and smaller pieces until all the answers
> are obvious and there are no places left for bugs
> to hide, passing the results back to build your
> final solution and keeping the pieces generic
> and reuseable.
>
> --
> Hugh Bothwell [EMAIL PROTECTED] Kingston ON Canada
> v3.1 GCS/E/AT d- s+: a- C+++ L++>+++$ P+ E- W+++$ N++ K? w++ M PS+
> PE++ Y+ PGP+ t-- 5++ !X R+ tv b DI+++ D-(++) G+ e(++) h-- r- y+
>
>
>



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



Re: [PHP] functions, opinion...

2003-06-16 Thread Leif K-Brooks
Dan Joseph wrote:

Hi,

   Just kind of curious what people think.  In your opinion,
should a function avoid output?  What I mean by that, is should a
function on "do something" without having echo or printf commands in it?
This is something I've been thinking about lately to improve my
programming style.  Opinions?
-Dan Joseph

 

Most functions I use don't output anything, but there's always going to 
be a case where a rule must be broken.

--
The above message is encrypted with double rot13 encoding.  Any unauthorized attempt 
to decrypt it will be prosecuted to the full extent of the law.


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


Re: [PHP] functions, opinion...

2003-06-16 Thread Hugh Bothwell
"Dvdmandt" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Or you could just temporarily enable ob... That's what I do when I have a
> function that needs to return lots of HTML containing many ' and "... I
know
> it's possible to use \ as well, but ob is somewhat easier then...


You're missing the point.  Output buffering can be useful,
but it is an entirely separate issue from the functional
programming style these two are endorsing
(and with which I wholeheartedly agree).

Too many people learned programming in the
BASIC school, writing 'do this, then add this, then
append that and the other' programs and ending
up with five-page subroutines.

A bit of experience with LISP or ML or FORTH
can be a wonderful thing; you start to see how
to simplify your problems, breaking them into
smaller and smaller pieces until all the answers
are obvious and there are no places left for bugs
to hide, passing the results back to build your
final solution and keeping the pieces generic
and reuseable.

--
Hugh Bothwell [EMAIL PROTECTED] Kingston ON Canada
v3.1 GCS/E/AT d- s+: a- C+++ L++>+++$ P+ E- W+++$ N++ K? w++ M PS+
PE++ Y+ PGP+ t-- 5++ !X R+ tv b DI+++ D-(++) G+ e(++) h-- r- y+




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



Re: [PHP] functions, opinion...

2003-06-16 Thread DvDmanDT
Or you could just temporarily enable ob... That's what I do when I have a
function that needs to return lots of HTML containing many ' and "... I know
it's possible to use \ as well, but ob is somewhat easier then...
"John W. Holmes" <[EMAIL PROTECTED]> skrev i meddelandet
news:[EMAIL PROTECTED]
> Rolf Brusletto wrote:
>  >>Just kind of curious what people think.  In your opinion,
>  >> should a function avoid output?  What I mean by that, is should a
>  >> function on "do something" without having echo or printf commands in
it?
>  >> This is something I've been thinking about lately to improve my
>  >> programming style.  Opinions?
>  >
> > My personal opinion, which shows in all my code writing is to never echo
> > inside a function. always return the data whether it be string, array,
> > or boolean... I've always left echoing up to the actual page showing the
> > data. That way if you have two seperate pages that need to display the
> > data differently, you can use the same function, and just format it as
> > needed on the pages.
>
> I'll second that; I do the same. If you don't do it this way, you'll
> find yourself re-writing a function sooner or later because you need it
> to return the data instead of displaying it.
>
> -- 
> ---John Holmes...
>
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
>
> PHP|Architect: A magazine for PHP Professionals – www.phparch.com
>
>
>
>



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



Re: [PHP] functions, opinion...

2003-06-16 Thread John W. Holmes
Rolf Brusletto wrote:
>>Just kind of curious what people think.  In your opinion,
>> should a function avoid output?  What I mean by that, is should a
>> function on "do something" without having echo or printf commands in it?
>> This is something I've been thinking about lately to improve my
>> programming style.  Opinions?
>
My personal opinion, which shows in all my code writing is to never echo 
inside a function. always return the data whether it be string, array, 
or boolean... I've always left echoing up to the actual page showing the 
data. That way if you have two seperate pages that need to display the 
data differently, you can use the same function, and just format it as 
needed on the pages.
I'll second that; I do the same. If you don't do it this way, you'll 
find yourself re-writing a function sooner or later because you need it 
to return the data instead of displaying it.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

PHP|Architect: A magazine for PHP Professionals – www.phparch.com





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


Re: [PHP] functions, opinion...

2003-06-16 Thread Rolf Brusletto
Dan -

My personal opinion, which shows in all my code writing is to never echo 
inside a function. always return the data whether it be string, array, 
or boolean... I've always left echoing up to the actual page showing the 
data. That way if you have two seperate pages that need to display the 
data differently, you can use the same function, and just format it as 
needed on the pages.

Rolf Brusletto
http://www.phpExamples.net
Dan Joseph wrote:

Hi,

   Just kind of curious what people think.  In your opinion,
should a function avoid output?  What I mean by that, is should a
function on "do something" without having echo or printf commands in it?
This is something I've been thinking about lately to improve my
programming style.  Opinions?
-Dan Joseph

 



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


Re: [PHP] Functions and arguments

2003-01-29 Thread Blaine von Roeder

> > What happens when you run this?
I made some tweaks to the way I was running sessions, and now it works. I'm
still getting an error unfortunately, but it's less conspicuous and spammy
this time:

  Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in
/home/virtual/site125/fst/var/www/html/atracker/assignments/index.php on
line 33

The line(and dependent lines) in question is as follows:
:CODE:

$classes = mysql_query("SELECT period1, period2, period3, period4, period5,
period6, periodpaws, period0 FROM students WHERE id = $id");

$classes_array = mysql_fetch_array($classes);

   $class_info = mysql_query("SELECT * FROM classes WHERE $id =
".$classes_array[period0]);

   $class_info_array = mysql_fetch_array($class_info);
:CODE:

Thanks for the help,
Blaine von Roeder



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




Re: [PHP] Functions and arguments

2003-01-29 Thread Matt

- Original Message -
From: "R0x0r Mc0wnage" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, January 29, 2003 8:49 PM
Subject: Re: [PHP] Functions and arguments


> Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result
> resource in
> /home/virtual/site125/fst/var/www/html/atracker/assignments/index.php on
> line 15
>   Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
> result resource in
> /home/virtual/site125/fst/var/www/html/atracker/assignments/index.php on
> line 33
> Would I be getting this kind of error if $id was not set correctly? I was
> doing a bit of testing and for some reason my sessions aren't registering
or
> something :\

Yes.  You should always check the result  of the mysql_query statement, and
take some action if it returns false.  False means the query failed (and not
that there were no rows returned), so you should at least log the error from
mysql_error(), maybe email it to someone that can do something about it, and
perhaps do more depending on the situation.  You shouldn't echo
mysql_error() out to the browser, except while debugging, so as to prevent
information leakage to the bad guys.



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




Re: [PHP] Functions and arguments

2003-01-29 Thread R0x0r Mc0wnage
> What happens when you run this?
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in
/home/virtual/site125/fst/var/www/html/atracker/assignments/index.php on
line 15

  ID Number Name Created by Created on Due on Class

  Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in
/home/virtual/site125/fst/var/www/html/atracker/assignments/index.php on
line 33



There's a lot more mysql_fetch_array warnings, with varying lines. The two
lines in question above are:

:CODE:
$classes = mysql_query("SELECT period1, period2, period3, period4, period5,
period6, periodpaws, period0 FROM students WHERE id = $id");

$classes_array = mysql_fetch_array($classes);
:CODE:

:CODE:
   $class_info = mysql_query("SELECT * FROM classes WHERE $id =
".$classes_array[period0]);
   $class_info_array = mysql_fetch_array($class_info);
:CODE:

Would I be getting this kind of error if $id was not set correctly? I was
doing a bit of testing and for some reason my sessions aren't registering or
something :\



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




Re: [PHP] Functions and arguments

2003-01-28 Thread Jason Wong
On Wednesday 29 January 2003 13:31, Blaine von Roeder wrote:

> I'm working on the part of the site to parse your session for student id,
> check the students table for your class listing(named period1, period2,
> period3, etc), and then check the classes table based on the id numbers in
> your students.period1(etc) fields. I've created a function for parsing the
> assignments table against your session id and such, and pulling up the
> posted assignments. However this is where I hit a brick wall.
>
> I need to pass the class_id argument to the function. I.e. class_id 1234 to
> pull up all the matching assignments on class 1234. I don't know how to
> pass it dynamically though, based upon the settings in your
> students.user.period1.
>
> I was thinking along the lines of using a for statement, with a nested
> switch. Here's what I've rather conjured up thusfar, which I can't get to
> work.
>
> :CODE:
>
> for($i = 0;$i < 7;$i++) {
>   switch ($i) {
>case 0:
>$class_info = mysql_query("SELECT * FROM classes WHERE $id =
> ".$classes_array[period0]);
>$class_info_array = mysql_fetch_array($classes);
>$class_id = $class_info_array[id];
>display_class_assign($class_id)
>
> :CODE:
>
> The cases are all the same, except period0 is replaced with period1,
> period2, etc. up to case 7 which is periodpaws. Classes_array refers to
>
> this:
> :CODE:
>
> $classes = mysql_query("SELECT period1, period2, period3, period4, period5,
> period6, periodpaws, period0 FROM students WHERE id = $id");
>
> $classes_array = mysql_fetch_array($classes);
>
> :CODE:
>
> I can post the code for the function if I need to, but I don't think that's
> where the problem lies. The way I've set it up it works fine if i do
> display_class_assigns(1234) and it pulls up the fields, displays, etc
> perfectly.

What happens when you run this?

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
Swipple's Rule of Order:
He who shouts the loudest has the floor.
*/


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




Re: [PHP] FUNCTIONS

2002-08-19 Thread Jason Wong

On Monday 19 August 2002 22:51, Georgie Casey wrote:
> its supposed to write a MIDI file from some music notes, the start of the
> MIDI file is grand but the end has some of the MIDI from the next database
> record!

Instead of keeping us guessing and indulging in idle speculation as to what 
your problem might be, please post your code.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
If you can't get your work done in the first 24 hours, work nights.
*/


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




Re: [PHP] FUNCTIONS

2002-08-19 Thread Georgie Casey

its supposed to write a MIDI file from some music notes, the start of the
MIDI file is grand but the end has some of the MIDI from the next database
record!



"Jay Blanchard" <[EMAIL PROTECTED]> wrote in message
002e01c2479f$1dbf6590$8102a8c0@000347D72515">news:002e01c2479f$1dbf6590$8102a8c0@000347D72515...
> [snip]
> i wrote a function do write a file for me on info taken from a db, and
wrote
> a script with a for loop going through every row in the db, and calling
the
> function. so the function is called about 200 times. but i'm getting weird
> results, the files are corrupted. its grand when i just go one at a time.
so
> i'm assuming variable values must have been left set from the las for
loop.
> so how do i clear ALL variables in the function??
> [/snip]
>
> What do you mean by "corrupted"? It should be simple;
>
> Open the file
>   while file open
> read a record from the database into the file
>   when no more records
> close file
>
> Maybe you need to place a proper newline character at the end of each
record
> or something like that. Can we have some more information to go on?
>
> Thanks!
>
> Jay
>
> ***
> * Texas PHP Developers Conf  Spring 2003  *
> * T Bar M Resort & Conference Center  *
> * New Braunfels, Texas*
> * San Antonio Area PHP Developers Group   *
> * Interested? Contact [EMAIL PROTECTED] *
> ***
>
>



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




Re: [PHP] FUNCTIONS

2002-08-19 Thread Georgie Casey

yea, but what about varibales in the actual function??
"Met" <[EMAIL PROTECTED]> wrote in message
003c01c2479f$ee948c40$6901a8c0@SURVIVAL">news:003c01c2479f$ee948c40$6901a8c0@SURVIVAL...
> In the top of the loop, before you set the variables from the database
> do this.
>
> unset($variable);
>
> OR
>
> $variable = "";
>
> Either will do.
>
> ~ Matthew
>
> -Original Message-
> From: Georgie Casey [mailto:[EMAIL PROTECTED]]
> Sent: Monday, August 19, 2002 10:30 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] FUNCTIONS
>
>
> i wrote a function do write a file for me on info taken from a db, and
> wrote a script with a for loop going through every row in the db, and
> calling the function. so the function is called about 200 times. but i'm
> getting weird results, the files are corrupted. its grand when i just go
> one at a time. so i'm assuming variable values must have been left set
> from the las for loop. so how do i clear ALL variables in the function??
>
> TANX
>
>
>
> --
> 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




RE: [PHP] FUNCTIONS

2002-08-19 Thread MET

In the top of the loop, before you set the variables from the database
do this.

unset($variable);

OR

$variable = "";

Either will do.

~ Matthew

-Original Message-
From: Georgie Casey [mailto:[EMAIL PROTECTED]] 
Sent: Monday, August 19, 2002 10:30 AM
To: [EMAIL PROTECTED]
Subject: [PHP] FUNCTIONS


i wrote a function do write a file for me on info taken from a db, and
wrote a script with a for loop going through every row in the db, and
calling the function. so the function is called about 200 times. but i'm
getting weird results, the files are corrupted. its grand when i just go
one at a time. so i'm assuming variable values must have been left set
from the las for loop. so how do i clear ALL variables in the function??

TANX



-- 
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




RE: [PHP] FUNCTIONS

2002-08-19 Thread Jay Blanchard

[snip]
i wrote a function do write a file for me on info taken from a db, and wrote
a script with a for loop going through every row in the db, and calling the
function. so the function is called about 200 times. but i'm getting weird
results, the files are corrupted. its grand when i just go one at a time. so
i'm assuming variable values must have been left set from the las for loop.
so how do i clear ALL variables in the function??
[/snip]

What do you mean by "corrupted"? It should be simple;

Open the file
  while file open
read a record from the database into the file
  when no more records
close file

Maybe you need to place a proper newline character at the end of each record
or something like that. Can we have some more information to go on?

Thanks!

Jay

***
* Texas PHP Developers Conf  Spring 2003  *
* T Bar M Resort & Conference Center  *
* New Braunfels, Texas*
* San Antonio Area PHP Developers Group   *
* Interested? Contact [EMAIL PROTECTED] *
***



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




[PHP] Re: PHP Functions Essential Reference??

2002-07-18 Thread Richard Lynch

>does anyone have a copy of the electronic version (free, i believe?) of 
>the book "PHP Functions Essential Reference" ?
>the website http://www.php-er.com has been down and i am trying to 
>locate it...

http://php.net ? :-)

Given the price of the book, just buy a paper copy :-)

-- 
Like Music?  http://l-i-e.com/artists.htm


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




Re: [PHP] Functions list

2002-07-09 Thread David Otton

On Tue, 9 Jul 2002 15:05:21 -0300, you wrote:

>I have the PHP manual in my PDA but its extraordinary large to search
>for a function. Does anybody know a Functions list that I can download
>for my PDA? I’m looking for something which shows the function and a
>short description of what it works for.

There's a PHP Pocket Reference in this office... (O'Reilly, ISBN
1565927699). You might find that does the job better than a PDA.

The text is also online:
http://safari.oreilly.com/main.asp?bookname=phppr&cnode=1


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




Re: [PHP] functions

2002-04-12 Thread Andrey Hristov



HTH

Regards,
Andrey Hristov

- Original Message - 
From: "Alia Mikati" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, April 12, 2002 4:37 PM
Subject: [PHP] functions


> hi
> i would like now how can we call a function within another function in 
> php?
> thx a lot
> 
> 
> 
> -- 
> 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




RE: [PHP] functions

2002-04-12 Thread Jon Haworth

Hi Alia,

> i would like now how can we call a function within another function in 
> php?

The same way you'd call it from outside a function :-)

";
world();

?>

...should output

hello
hello world

Cheers
Jon

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




RE: [PHP] functions

2002-04-12 Thread Caspar Kennerdale

function firstfunction(){

code;
code;
code;

secondfunction();

}

-Original Message-
From: Alia Mikati [mailto:[EMAIL PROTECTED]]
Sent: 12 April 2002 06:38
To: [EMAIL PROTECTED]
Subject: [PHP] functions


hi
i would like now how can we call a function within another function in 
php?
thx a lot



-- 
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




RE: [PHP] Functions

2002-02-13 Thread Narvaez, Teresa

Try the phpinfo() function: 

Example: 
PHP Test




-Teresa
 
-Original Message-
From: Jason Whitaker [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 13, 2002 4:15 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Functions


Is there a website that lists all the default functions and variables?

EI: $REMOTE_ADDR AND $PHP_SELF

--

Jason Whitaker



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



RE: [PHP] Functions

2002-02-13 Thread Daniel Kushner

http://www.php.net/manual/en/language.variables.predefined.php
http://www.php.net/manual/en/funcref.php

> -Original Message-
> From: Jason Whitaker [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, February 13, 2002 4:15 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Functions
> 
> 
> Is there a website that lists all the default functions and variables?
> 
> EI: $REMOTE_ADDR AND $PHP_SELF
> 
> --
> 
> Jason Whitaker
> 
> 
> 
> -- 
> 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




RE: [PHP] functions...

2002-01-09 Thread Robert V. Zwink

More about this here:
http://www.php.net/manual/en/function.func-get-arg.php

Robert Zwink
http://www.zwink.net/daid.php

-Original Message-
From: Chris Hall [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 08, 2002 9:48 PM
To: [EMAIL PROTECTED]
Subject: [PHP] functions...


function lala() {

do i HAVE to define a variable or argument 

function lala($var) {

or can i use it like:

lala($stmt);

will $stmt become part of the function?


--
Chris Hall
hardwired industries



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] functions...

2002-01-08 Thread Martin Towell

it's possible to pass a variable number of parameters to a function

  $num = func_num_args();
  for ($i = 1; $i < $num; $i++)
  {
$arg = func_get_arg($i);
  }

try looking at these...

-Original Message-
From: Chris Hall [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 09, 2002 1:48 PM
To: [EMAIL PROTECTED]
Subject: [PHP] functions...


function lala() {

do i HAVE to define a variable or argument 

function lala($var) {

or can i use it like:

lala($stmt);

will $stmt become part of the function?


--
Chris Hall
hardwired industries



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



RE: [PHP] functions returning arrays II

2001-08-27 Thread Robert V. Zwink

The line:
echo "$r[ $i ]";

does not need quotation marks.  You should change it to:
echo $r[ $i ];

I removed the quotation marks and your script ran fine on my server.  If
this doesn't help post more information.

Robert Zwink
http://www.zwink.net/daid.net

-Original Message-
From: Frank Loewenthal [mailto:[EMAIL PROTECTED]]
Sent: Friday, August 24, 2001 11:44 AM
To: [EMAIL PROTECTED]
Subject: [PHP] functions returning arrays II


A lot of answers about the typing error
$r[ i ] resp. $r[ $i ]

Sorry, this was only wrong in my mail. But this is not the solution.


Hi

Perhaps I am confused, but is it not possible to return arrays in PHP?

Example:

function getArray() {
$ret = array('hallo','you');
return $ret;
}

$r = getArray();

for( $i=0;$i < count($r); $i++)
echo "$r[ $i ]";

Does not work! The array shows 2 Elements, but they are emty

Hm... Where is do mistake?

Regards
Frank




--
SFI Technology Services AG
Dr. F. Loewenthal
Stettbachstrasse 10
CH-8600 Dübendorf
Switzerland

[EMAIL PROTECTED]
www.sfi.ch
+41/1-824 49 00

---

--
SFI Technology Services AG
Dr. F. Loewenthal
Stettbachstrasse 10
CH-8600 Dübendorf
Switzerland

[EMAIL PROTECTED]
www.sfi.ch
+41/1-824 49 00

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

---

--
SFI Technology Services AG
Dr. F. Loewenthal
Stettbachstrasse 10
CH-8600 Dübendorf
Switzerland

[EMAIL PROTECTED]
www.sfi.ch
+41/1-824 49 00

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] functions?

2001-07-06 Thread [EMAIL PROTECTED]

on 7/6/01 11:36 AM, rick at [EMAIL PROTECTED] wrote:

> while ($row = mysql_fetch_row ($result)) {
> $map_list .= "$row[0]";  }
> }
> return $map_list;


Thanks Rick! This worked great.

I guess I'm right in assuming that all you can get back from a function is
one big string return. I've tried passing varibles to function and gave up
on it.


global.inc






mainfile.php3




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] functions?

2001-07-06 Thread rick

instead of returning that line, put it into some variable... like:

while ($row = mysql_fetch_row ($result)) {
  $map_list .= "$row[0]";  }
}
return $map_list;

- Original Message -
From: <[EMAIL PROTECTED]>
To: "'Php-General (E-Mail)" <[EMAIL PROTECTED]>
Sent: Friday, July 06, 1979 8:27 AM
Subject: [PHP] functions?


> Okay there is a file called global.inc
>
> 
> // display a list from the DB
>
> function list_of_maps () {
>
> db_connect ();
> $sql = "SELECT mapname,rowid FROM maps";
> $result = mysql_query($sql);
>
> while ($row = mysql_fetch_row ($result)) {
> return "$row[0]";  }
>
> }
>
>
>
> ?>
>
> But when I call it like this:
>
> 
> include('global.inc');
> echo list_of_maps ();
>
> ?>
>
> It only shows the first result from the db... How do I get it to list them
> all?
>
>
> Susan
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Functions.

2001-04-24 Thread Matt McClanahan

On Tue, Apr 24, 2001 at 03:06:40PM +0200, Anders Clerwall wrote:

> Hi,
> Is there a tutorial of some sort on how I add function sets to PHP4?
> I've searched the net for more info about this other than what the PHP4.x
> manual says, and I saw some reference to freshmeat, but I couldn't find
> that.
> Any help appreciated, thanks!

If you mean writing functions in PHP, that would be in the manual:

http://www.php.net/manual/en/functions.php

If you mean writing built-in functions (at the same level of
mysql_connect, array_reverse, etc) then you want

http://www.zend.com/zend/api.php

Or the README.SELF-CONTAINED-EXTENSIONS which is included in the PHP
source.

Matt

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] functions????

2001-01-27 Thread Markus Fischer


Have you tried defining those function before actually
using them ? Btw, case "pf" and function 'profile()' does not
really match you definition with function 'pf()' ??

m.

-- 
Markus Fischer,  http://josefine.ben.tuwien.ac.at/~mfischer/
EMail: [EMAIL PROTECTED]
PGP Public  Key: http://josefine.ben.tuwien.ac.at/~mfischer/C2272BD0.asc
PGP Fingerprint: D3B0 DD4F E12B F911 3CE1  C2B5 D674 B445 C227 2BD0

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] functions????

2001-01-27 Thread Kumanan

o

thanks

kumanan
"Nick Winfield" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> On Sun, 28 Jan 2001, Kumanan wrote:
>
> > Hi,
> >
> > i got problem with functions 
> >
> >
> > when i call the files with url//filename.php?action=pal
> >
> > all the time it says
> > Fatal error: Call to unsupported or undefined function pal_edit() in
> > /cfiles/memberlink.php on line 7
> >
>
> Declare your functions before the switch() statement - your switch
> statement is being executed before your functions even get a chance to be
> defined. :)
>
> e.g.
>
> function sayBlah() {
>   echo "Blah!";
> }
>
> switch($task) {
>   case do_stuff:
> sayBlah();
> break;
>   case other_stuff:
> # whatever
> break;
>   default:
> # whatever
> break;
> }
>
> Cheers,
>
> Nicky W..
> -[ [EMAIL PROTECTED] ]-
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] functions????

2001-01-27 Thread Joe Sheble (Wizaerd)

your function declarations must appear before you actually call them.

> code
> ...
>  function pf() { echo "profile"; }
> 
> function pal_edit() { echo "pal";  }

> switch ($action) {
> case "pf":
> profile();
> break;
> 
> case "pal":
>pal_edit();
> break;
> 
> }
> 
> 
> 
> ?>

Joseph E. Sheble
a.k.a. Wizaerd
Wizaerd's Realm
Canvas, 3D, Graphics, 
ColdFusion, PHP, and mySQL
http://www.wizaerd.com
=

> -Original Message-
> From: Kumanan [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, January 27, 2001 4:29 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] functions
> 
> 
> Hi,
> 
> i got problem with functions 
> 
> 
> when i call the files with url//filename.php?action=pal
> 
> all the time it says
> Fatal error: Call to unsupported or undefined function pal_edit() in
> /cfiles/memberlink.php on line 7
> 
> 
> 
> code
> ...
>  switch ($action) {
> case "pf":
> profile();
> break;
> 
> case "pal":
>pal_edit();
> break;
> 
> }
> 
> 
> function pf() { echo "profile"; }
> 
> function pal_edit() { echo "pal";  }
> 
> ?>
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] functions????

2001-01-27 Thread Nick Winfield

On Sun, 28 Jan 2001, Kumanan wrote:

> Hi,
> 
> i got problem with functions 
> 
> 
> when i call the files with url//filename.php?action=pal
> 
> all the time it says
> Fatal error: Call to unsupported or undefined function pal_edit() in
> /cfiles/memberlink.php on line 7
> 

Declare your functions before the switch() statement - your switch
statement is being executed before your functions even get a chance to be
defined. :)

e.g.

function sayBlah() {
  echo "Blah!";
}

switch($task) {
  case do_stuff:
sayBlah();
break;
  case other_stuff:
# whatever
break;
  default:
# whatever
break;
}

Cheers,

Nicky W..
-[ [EMAIL PROTECTED] ]-


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] <- functions returning multiple values Followup

2001-01-26 Thread Jerry Artman

Would it be easier to return an OBJECT populated with all the items one
might need?

On 01/22/2001 12:38 PM, "Matt McClanahan" <[EMAIL PROTECTED]> wrote:

> On Mon, 22 Jan 2001, Abe Asghar wrote:
> 
>> Hey there,
>> 
>>  is there a way that you can get a function to return multiple values. e.g.:
>> {and also how to access them}
>> 
>> function VarTest() {
>> 
>> return $var = 10;
>> 
>> return $var2 = 20;
>>  }
> 
> Functions can only return one variable.  However, you can return an array,
> which contains as many values as you need.
> 
> function vartest()
> {
>  $first = 10;
>  $second = 20;
> 
>  return Array($first,$second);
> }
> 
> Matt
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] <- functions returning multiple values: ->

2001-01-22 Thread Abe Asghar

Thanks Guys,



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] <- functions returning multiple values: ->

2001-01-22 Thread Matt McClanahan

On Mon, 22 Jan 2001, Abe Asghar wrote:

> Hey there,
> 
>  is there a way that you can get a function to return multiple values. e.g.:
> {and also how to access them}
> 
> function VarTest() {
> 
> return $var = 10;
> 
> return $var2 = 20;
>  }

Functions can only return one variable.  However, you can return an array,
which contains as many values as you need.

function vartest()
{
   $first = 10;
   $second = 20;

   return Array($first,$second);
}

Matt


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] <- functions returning multiple values: ->

2001-01-22 Thread Ignacio Vazquez-Abrams

On Mon, 22 Jan 2001, Abe Asghar wrote:

> Hey there,
>
>  is there a way that you can get a function to return multiple values. e.g.:
> {and also how to access them}
>
> function VarTest() {
>
> return $var = 10;
>
> return $var2 = 20;
>  }
>
> Thanks
>

function somefunc()
{
  return Array(10, 20);
};

-- 
Ignacio Vazquez-Abrams  <[EMAIL PROTECTED]>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Functions

2001-01-17 Thread Toby Butzon

> echo foo(dog);// outputs "This is a dog"

This is an example of using a "bareword" - PHP doesn't recognize _dog_ as
any sort of reserved word or constant, so it sends it like a quoted string.
I don't recommend using this because it's ambiguous whether you mean "dog"
or if _dog_ is a constant or whatever else is possible.

> echo foo('dog');// outputs "This is a dog"

Single-quoted string: this is good for strings that don't need to be
"interpretted" by the parser; it's the ideal way to pass the string 'dog'
to foo() in this case.

> echo foo("dog");// outputs "This is a dog"

Double-quoted string: this WILL be interpretted by the parser; for example,
if you had to pass the whole string "This is a dog" to the function, but
"dog" could actually be any word contained in $thing, then you'd do
something like this:

echo foo("This is a $thing");

Et cetera...

>
> Does it matter which way I pass my arguments to foo?  All arguments were
> passed as a string variable.

There are some very slight performance changes between these, but mostly
it's a matter of style.

--Toby


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Functions

2001-01-10 Thread Marcelo Gulin

Hi!

  ShowMessage();

regards
Marcelo Gulin

Augusto Cesar Castoldi escribió:
> 
> How do I use a function?
> 
> I did:
> 
> function ShowMessage {
>   echo "Show message...\n";
> }
> 
> How can I call the function now?
> 
> thanks,
> 
> Augusto Cesar Castoldi
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




  1   2   >