Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot redeclare class - Check if class already exists
    primarykey
    data
    text
    <p>I'm working with a script that is calling the same class twice and throwing the error:</p> <pre><code>Fatal: Cannot redeclare class urlConverter (/var/www/core/cache/includes/elements/modsnippet/23.include.cache.php:14) </code></pre> <p>I have tried placing the following code in:</p> <pre><code>if( !class_exists( 'urlConverter', false ) ) { $urlConverter = new urlConverter( $modx ); } </code></pre> <p>However doing that the CMS I'm working with is reporting an Error 500 and haven't been able to see in the logs why it's throwing that error.</p> <p>Does anyone know how to check if that class has already been declared correctly?</p> <p>Edit:</p> <p>I'm using a CMS so as a result the Class is housed in a Snippet and not an actual file. This is how they call their snippets:</p> <pre><code>$data['viewonlinelink'] = $this-&gt;modx-&gt;runSnippet( 'urlConverter', array( 'action' =&gt; 'encrypt', 'string' =&gt; http_build_query( $string ) ) ); </code></pre> <p>I need to call that a second time to get a different result.</p> <p>Edit2:</p> <p>Here is urlConverter:</p> <pre><code>&lt;?php class urlConverter { public $modx; public function __construct( modX &amp;$modx ) { $this-&gt;modx =&amp; $modx; } public function action( $scriptProperties ) { return $this-&gt;$scriptProperties['action']( $scriptProperties['string'] ); } private function encrypt( $str ) { return $str; } private function decrypt( $str ) { return $str; } } } $urlConverter = new urlConverter( $modx ); return $urlConverter-&gt;action( $scriptProperties ); </code></pre> <p>Now from another script I call the following:</p> <pre><code> $data['viewonlinelink'] = $this-&gt;modx-&gt;runSnippet( 'urlConverter', array( 'action' =&gt; 'encrypt', 'string' =&gt; http_build_query( $string ) ) ); $data['confirmonline'] = $this-&gt;modx-&gt;runSnippet( 'urlConverter', array( 'action' =&gt; 'encrypt', 'string' =&gt; http_build_query( $reversed ) ) ); </code></pre> <p>Which runs the function encrypt inside of my urlConverter class and I should receive two different results.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload