2016-10-19 104 views
0

獲取一個實例是這樣的:無法序列化和反序列化對象刪除對象元素PHP

$coreBootstrap = new PEP_Application_BootstrapCore(array('bootstrap' => $this)); 

接收到這個對象:

PEP_Application_BootstrapCore Object ([_bootstrap:protected] => Bootstrap Object ([_appNamespace:protected] => [_resourceLoader:protected] => [_application:protected] => PEP_Application Object ([_autoloader:protected] => PEP_Autoloader Object ([_autoloaders:protected] => Array ([0] => Zend_Application_Module_Autoloader Object ([_basePath:protected] => C:\LodgingPhp\com-ui-php\target\packaged-application\application [_components:protected] => Array ([Default_Controller_Action_Helper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers/actions/helpers [Default_Module] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules [Default_Model_DbTable] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/DbTable [Default_Model_Mapper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/mappers [Default_Form] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/forms [Default_Model] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models [Default_Plugin] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/plugins [Default_Service] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/services [Default_View_Helper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/helpers [Default_View_Filter] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/filters) [_defaultResourceType:protected] => model [_namespace:protected] => Default [_resourceTypes:protected] => Array ([actionhelper] => Array ([namespace] => Default_Controller_Action_Helper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers/actions/helpers) [module] => Array ([namespace] => Default_Module [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules) [dbtable] => Array ([namespace] => Default_Model_DbTable [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/DbTable) [mappers] => Array ([namespace] => Default_Model_Mapper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/mappers) [form] => Array ([namespace] => Default_Form [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/forms) [model] => Array ([namespace] => Default_Model [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models) [plugin] => Array ([namespace] => Default_Plugin [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/plugins) [service] => Array ([namespace] => Default_Service [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/services) [viewhelper] => Array ([namespace] => Default_View_Helper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/helpers) [viewfilter] => Array ([namespace] => Default_View_Filter [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/filters)))) [_defaultAutoloader:protected] => Array ([0] => PEP_Loader [1] => loadClass) [_fallbackAutoloader:protected] => [_internalAutoloader:protected] => Array ([0] => PEP_Autoloader Object *RECURSION* [1] => _autoload) [_namespaces:protected] => Array ([Zend_] => 1 [ZendX_] => 1 [WDPRO_] => 1 [PEP_] => 1 [controllers_helpers_] => 1 [Guzzle] => 1 [Symfony] => 1) [_namespaceAutoloaders:protected] => Array ([Default_] => Array ([0] => Zend_Application_Module_Autoloader Object ([_basePath:protected] => C:\LodgingPhp\com-ui-php\target\packaged-application\application [_components:protected] => Array ([Default_Controller_Action_Helper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers/actions/helpers [Default_Module] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules [Default_Model_DbTable] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/DbTable [Default_Model_Mapper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/mappers [Default_Form] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/forms [Default_Model] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models [Default_Plugin] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/plugins [Default_Service] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/services [Default_View_Helper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/helpers [Default_View_Filter] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/filters) [_defaultResourceType:protected] => model [_namespace:protected] => Default [_resourceTypes:protected] => Array ([actionhelper] => Array ([namespace] => Default_Controller_Action_Helper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers/actions/helpers) [module] => Array ([namespace] => Default_Module [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules) [dbtable] => Array ([namespace] => Default_Model_DbTable [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/DbTable) [mappers] => Array ([namespace] => Default_Model_Mapper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/mappers) [form] => Array ([namespace] => Default_Form [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/forms) [model] => Array ([namespace] => Default_Model [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models) [plugin] => Array ([namespace] => Default_Plugin [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/plugins) [service] => Array ([namespace] => Default_Service [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/services) [viewhelper] => Array ([namespace] => Default_View_Helper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/helpers) [viewfilter] => Array ([namespace] => Default_View_Filter [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/filters))))) [_suppressNotFoundWarnings:protected] => [_zfPath:protected] =>) [_bootstrap:protected] => Bootstrap Object *RECURSION* [_environment:protected] => local [_optionKeys:protected] => Array ([0] => phpsettings [1] => includepaths [2] => bootstrap [3] => resources [4] => deviceprofiling [5] => pluginpaths [6] => autoloadernamespaces) [_options:protected] => Array ([phpSettings] => Array ([log_errors] => 1 [date] => Array ([timezone] => America/New_York) [display_startup_errors] => 0 [display_errors] => 1 [error_reporting] => 32767 [error_log] => C:\LodgingPhp\com-ui-php\target/logs/php_error.log) [includePaths] => Array ([library] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/../library) [bootstrap] => Array ([path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/Bootstrap.php [class] => Bootstrap) [resources] => Array ([frontController] => Array ([controllerDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers [moduleDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules) [layout] => Array ([layoutPath] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/layouts/scripts) [setsystemtime] => Array ([load] =>) [session] => Array ([strict] =>) [modules] => Array ([0] => api [1] => tickets [2] => events [3] => passes [4] => plan [5] => resortaddons [6] => debugutils [7] => visa-instant-credit) [view] => [log] => Array ([logConfig] => /configs/log.ini) [stats] => Array ([serviceLogLevel] => INFO [requestResponseLogLevel] => DEBUG [viewLogLevel] => INFO [actionLogLevel] => INFO [appLogLevel] => INFO [memoryLogLevel] => DEBUG) [serviceSuccessLog] => Array ([logConfig] => /configs/serviceSuccessLog.ini)) [deviceprofiling] => Array ([cookieName] => WDPROView [timeToLive] => 604800 [cookiePath] =>/[enabled] => 1 [routeBlackList] => Array ([0] => /api [1] => /utils)) [pluginpaths] => Array ([PEP_Stats_Resource_] => PEP/Stats/Resource [PEP_Application_Resource_] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/../library/PEP/Application/Resource [Default_Resource_] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/resource) [autoloadernamespaces] => Array ([0] => WDPRO_ [1] => Zend_ [2] => PEP_ [3] => controllers_helpers_ [4] => Guzzle [5] => Symfony))) [_classResources:protected] => Array ([autoload] => _initAutoload [core] => _initCore [router] => _initRouter [servicestub] => _initServiceStub [mediaengineconfig] => _initMediaEngineConfig [viewhelpers] => _initViewHelpers [configurablestoreplugin] => _initConfigurableStorePlugin [languagesetupplugin] => _initLanguageSetupPlugin [keywordrouterplugin] => _initKeywordRouterPlugin [tripconfig] => _initTripConfig [dclkeepalive] => _initDclKeepAlive [helpconfig] => _initHelpConfig [analyticsgenericplugin] => _initAnalyticsGenericPlugin [postdispatchstatsdplugin] => _initPostDispatchStatsDPlugin [curoauthplugin] => _initCUROAuthPlugin [sessionserviceshdrplugin] => _initSessionServiceShdrPlugin) [_container:protected] => Zend_Registry Object ([storage:ArrayObject:private] => Array ([autoload] => Zend_Application_Module_Autoloader Object ([_basePath:protected] => C:\LodgingPhp\com-ui-php\target\packaged-application\application [_components:protected] => Array ([Default_Controller_Action_Helper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers/actions/helpers [Default_Module] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules [Default_Model_DbTable] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/DbTable [Default_Model_Mapper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/mappers [Default_Form] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/forms [Default_Model] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models [Default_Plugin] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/plugins [Default_Service] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/services [Default_View_Helper] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/helpers [Default_View_Filter] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/filters) [_defaultResourceType:protected] => model [_namespace:protected] => Default [_resourceTypes:protected] => Array ([actionhelper] => Array ([namespace] => Default_Controller_Action_Helper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers/actions/helpers) [module] => Array ([namespace] => Default_Module [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules) [dbtable] => Array ([namespace] => Default_Model_DbTable [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/DbTable) [mappers] => Array ([namespace] => Default_Model_Mapper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models/mappers) [form] => Array ([namespace] => Default_Form [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/forms) [model] => Array ([namespace] => Default_Model [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/models) [plugin] => Array ([namespace] => Default_Plugin [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/plugins) [service] => Array ([namespace] => Default_Service [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/services) [viewhelper] => Array ([namespace] => Default_View_Helper [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/helpers) [viewfilter] => Array ([namespace] => Default_View_Filter [path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/views/filters))))) [_environment:protected] => [_optionKeys:protected] => Array ([0] => phpsettings [1] => includepaths [2] => bootstrap [3] => resources [4] => deviceprofiling [5] => pluginpaths [6] => autoloadernamespaces) [_options:protected] => Array ([phpSettings] => Array ([log_errors] => 1 [date] => Array ([timezone] => America/New_York) [display_startup_errors] => 0 [display_errors] => 1 [error_reporting] => 32767 [error_log] => C:\LodgingPhp\com-ui-php\target/logs/php_error.log) [includePaths] => Array ([library] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/../library) [bootstrap] => Array ([path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/Bootstrap.php [class] => Bootstrap) [resources] => Array ([frontController] => Array ([controllerDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers [moduleDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules) [layout] => Array ([layoutPath] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/layouts/scripts) [setsystemtime] => Array ([load] =>) [session] => Array ([strict] =>) [modules] => Array ([0] => api [1] => tickets [2] => events [3] => passes [4] => plan [5] => resortaddons [6] => debugutils [7] => visa-instant-credit) [view] => [log] => Array ([logConfig] => /configs/log.ini) [stats] => Array ([serviceLogLevel] => INFO [requestResponseLogLevel] => DEBUG [viewLogLevel] => INFO [actionLogLevel] => INFO [appLogLevel] => INFO [memoryLogLevel] => DEBUG) [serviceSuccessLog] => Array ([logConfig] => /configs/serviceSuccessLog.ini)) [deviceprofiling] => Array ([cookieName] => WDPROView [timeToLive] => 604800 [cookiePath] =>/[enabled] => 1 [routeBlackList] => Array ([0] => /api [1] => /utils)) [pluginpaths] => Array ([PEP_Stats_Resource_] => PEP/Stats/Resource [PEP_Application_Resource_] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/../library/PEP/Application/Resource [Default_Resource_] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/resource) [autoloadernamespaces] => Array ([0] => WDPRO_ [1] => Zend_ [2] => PEP_ [3] => controllers_helpers_ [4] => Guzzle [5] => Symfony)) [_pluginLoader:protected] => [_pluginResources:protected] => Array ([layout] => Array ([layoutPath] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/layouts/scripts) [setsystemtime] => Array ([load] =>) [session] => Array ([strict] =>) [modules] => Array ([0] => api [1] => tickets [2] => events [3] => passes [4] => plan [5] => resortaddons [6] => debugutils [7] => visa-instant-credit) [view] => [log] => Array ([logConfig] => /configs/log.ini) [stats] => Array ([serviceLogLevel] => INFO [requestResponseLogLevel] => DEBUG [viewLogLevel] => INFO [actionLogLevel] => INFO [appLogLevel] => INFO [memoryLogLevel] => DEBUG) [serviceSuccessLog] => Array ([logConfig] => /configs/serviceSuccessLog.ini) [frontcontroller] => Zend_Application_Resource_Frontcontroller Object ([_front:protected] => [_bootstrap:protected] => Bootstrap Object *RECURSION* [_options:protected] => Array ([controllerDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers [moduleDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules) [_skipOptions:protected] => Array ([0] => options [1] => config))) [_run:protected] => Array ([0] => autoload) [_started:protected] => Array ([core] => 1)) [_options:protected] => Array () [_skipOptions:protected] => Array ([0] => options [1] => config)) 

我需要刪除setsystemtime部分:

[setsystemtime] => Array ([load] =>) 

但我無法達到它,我試圖鑄造數組,然後做一個array_search,但我得到:「它帶來了數組字符串轉換「:

$coreBootstrap = array_merge(array_diff((array) $coreBootstrap, array('setsystemtime'))); 

我也試過如下:

$a = serialize($coreBootstrap); 
    $x =json_encode($a); 
    $x= str_replace('s:13:\"setsystemtime\";a:1:{s:4:\"load\";s:1:\"1\";}', "", $x); 
    $a = json_decode($x, true); 
    $a = unserialize($a); // this brings an error and page doesnt load 
    // $logger->info($a); 
    $a = (object) $a; 
    $logger->info($x); 
// $a->init(); 
    $coreBootstrap->init(); 

而且 這是PHP 5.4.4

任何想法? 謝謝!

+1

爲什麼不將'$ coreBootstrap'強制轉換爲數組,然後將其序列化或將其轉換回對象,而不是嘗試轉換數組? – Xorifelse

+0

請問你能告訴我這是怎麼回事?謝謝 – arnoldssss

+0

這是一個對象。不是一個數組。不要把它當作一個數組來對待,否則你會毀掉這個對象。 –

回答

1

而不是試圖轉換數組,爲什麼不將$coreBootstrap轉換爲數組,然後取消設置索引,然後序列化或將其轉換回對象?

// this should be done for each subindex that is also an object. 
$a = (array) $coreBootstrap; 
unset($a[..the index..]); 
$a = (object) $a; 

我們也可以嘗試去爲一個完整的遞歸的轉換,但是這可能不會想:

$a = json_decode(json_encode($coreBootstrap, JSON_FORCE_OBJECT), false); 

它只是一個大陣列處理包含數組的和對象時,最好專門做。

$a = (array) $coreBootstrap->objectvar->objectvar; 
unset($a[idofindex]); 
$a = (object) $coreBootstrap->objectvar->objectvar; 
$coreBootstrap->objectvar->objectvar = $a; 
+0

好吧,讓我試試謝謝 – arnoldssss

+0

它不工作...三個要素setsystemtime仍然存在我會把輸出的問題 – arnoldssss

+0

http://collabedit.com/uxbfh – arnoldssss