php-general Digest 17 May 2011 10:52:12 -0000 Issue 7314

Topics (messages 312816 through 312820):

Consistent Class Renaming (Simple Refactoring)
        312816 by: Tony Mak
        312817 by: Tony Mak
        312818 by: Richard Quadling
        312819 by: Paul M Foster

Session question
        312820 by: Paul Halliday

Administrivia:

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

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

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


----------------------------------------------------------------------
--- Begin Message ---
Hi there,

i have following problem:

Assume we have a "cron.php" which is called every hour by a cron job. This cron.php should then be used to execute other php-scripts "script1.php", "script2.php".

For a pitty our server has Safe-Mode activated so we arent able to shell_exec / exec those files. So we came up with the idea: Lets include those scripts using include(). But this lead us to another problem: Namespace conflicts (our server is running php 2.7.2) especially with classes and constants.

Example:
<<script1.php>>
<?php
class A {
  public function test(){ echo "im class A at script 1"; }
}
?>

<<script2.php>>
<?php
class A {
  public function test(){ echo "im class A at script 2"; }
}
?>

<<cron.php>>
<?php

include('./script1.php');
include('./script2.php');
?>


Cron.php will raise a "cannot redefine class A" error.

So my idea is to continously rename every occurence of class names and constants in the scripts by adding a suffix (ie. class A_123 and class A_234). Do you have an idea how to implement this during the deployment step?

Sincerly yours

--- End Message ---
--- Begin Message ---
Hi there,

i have following problem:

Assume we have a "cron.php" which is called every hour by a cron job. This cron.php should then be used to execute other php-scripts "script1.php", "script2.php".

For a pitty our server has Safe-Mode activated so we arent able to shell_exec / exec those files. So we came up with the idea: Lets include those scripts using include(). But this lead us to another problem: Namespace conflicts (our server is running php 2.7.2) especially with classes and constants.

Example:
<<script1.php>>
<?php
class A {
  public function test(){ echo "im class A at script 1"; }
}
?>

<<script2.php>>
<?php
class A {
  public function test(){ echo "im class A at script 2"; }
}
?>

<<cron.php>>
<?php

include('./script1.php');
include('./script2.php');
?>


Cron.php will raise a "cannot redefine class A" error.

So my idea is to continously rename every occurence of class names and constants in the scripts by adding a suffix (ie. class A_123 and class A_234). Do you have an idea how to implement this during the deployment step?

Sincerly yours

--- End Message ---
--- Begin Message ---
On 16 May 2011 23:12, Tony Mak <[email protected]> wrote:
> Hi there,
>
> i have following problem:
>
> Assume we have a "cron.php" which is called every hour by a cron job. This
> cron.php should then be used to execute other php-scripts "script1.php",
> "script2.php".
>
> For a pitty our server has Safe-Mode activated so we arent able to
> shell_exec / exec those files. So we came up with the idea: Lets include
> those scripts using include(). But this lead us to another problem:
> Namespace conflicts (our server is running php 2.7.2) especially with
> classes and constants.
>
> Example:
> <<script1.php>>
> <?php
> class A {
>  public function test(){ echo "im class A at script 1"; }
> }
> ?>
>
> <<script2.php>>
> <?php
> class A {
>  public function test(){ echo "im class A at script 2"; }
> }
> ?>
>
> <<cron.php>>
> <?php
>
> include('./script1.php');
> include('./script2.php');
> ?>
>
>
> Cron.php will raise a "cannot redefine class A" error.
>
> So my idea is to continously rename every occurence of class names and
> constants in the scripts by adding a suffix (ie. class A_123 and class
> A_234). Do you have an idea how to implement this during the deployment
> step?
>
> Sincerly yours
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

"2.7.2"? I'm guessing 5.7.2.

The only way I could think of would be to use namespaces, but that
would involve some reworking.

And only for V5.3+

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

--- End Message ---
--- Begin Message ---
On Mon, May 16, 2011 at 11:05:07PM +0200, Tony Mak wrote:

> Hi there,
> 
> i have following problem:
> 
> Assume we have a "cron.php" which is called every hour by a cron
> job. This cron.php should then be used to execute other php-scripts
> "script1.php", "script2.php".
> 
> For a pitty our server has Safe-Mode activated so we arent able to
> shell_exec / exec those files. So we came up with the idea: Lets
> include those scripts using include(). But this lead us to another
> problem: Namespace conflicts (our server is running php 2.7.2)
> especially with classes and constants.

Pretty sure you're *not* running PHP 2.7.2. If you are, give up now.

> 
> Example:
> <<script1.php>>
> <?php
> class A {
>   public function test(){ echo "im class A at script 1"; }
> }
> ?>
> 
> <<script2.php>>
> <?php
> class A {
>   public function test(){ echo "im class A at script 2"; }
> }
> ?>
> 
> <<cron.php>>
> <?php
> 
> include('./script1.php');
> include('./script2.php');
> ?>
> 
> 
> Cron.php will raise a "cannot redefine class A" error.

Well of course, you would get that error. But I'm completely lost beyond
that point. Why must both scripts use the same class names in them? Why
not call the class in script2.php "B" instead of "A"? I'm guessing you
left out a huge piece of explanation here.

> 
> So my idea is to continously rename every occurence of class names
> and constants in the scripts by adding a suffix (ie. class A_123 and
> class A_234). Do you have an idea how to implement this during the
> deployment step?

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

--- End Message ---
--- Begin Message ---
Is it OK to have session_start as an include?

I have something like this:

// Session init
session_start();

function sKill() {
    session_destroy();
    session_unset();
    header ("Location: login.php");
    exit();
}

function sInt() {
     header ("Location: login.php");
     exit();
}

if (!(isset($_SESSION['sLogin']) && $_SESSION['sLogin'] != '')) {
     sKill();
}

// Session variables
if (!isset($_SESSION['sUser']))  { sInt(); }  else { $sUser  =
$_SESSION['sUser'];}
if (!isset($_SESSION['sEmail'])) { sInt(); }  else { $sEmail =
$_SESSION['sEmail'];}
if (!isset($_SESSION['sType']))  { sInt(); }  else { $sType  =
$_SESSION['sType'];}
if (!isset($_SESSION['sTime']))  { sInt(); }  else { $sTime  =
$_SESSION['sTime'];}
if (!isset($_REQUEST['id']))     { $id = 0; } else { $id     = $_REQUEST['id'];}

// Kill the session if the ids dont match.
if ($id != $_SESSION['id']) {
    sKill();
}

// Kill the session if timeout is exceeded.
if (isset($_SESSION['LAST_ACTIVITY']) && (time() -
$_SESSION['LAST_ACTIVITY'] > $sTime)) {
    sKill();
}

Can I just call this session.php and include it at the beginning of each file?

-- 
Paul Halliday
http://www.squertproject.org/

--- End Message ---

Reply via email to